Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to clean input and textarea fields
Old 01-27-2009, 03:58 PM How to clean input and textarea fields
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
I need some advice again. How would you go about a problem like this?


I have a form that I put through a validation process. There are three fields. If the validation fails, the form displays an error and the user has a chance to correct it. That means whatever he typed into the fields will stay there so he doesn't have to re-type everything again.


Now my problem is that once the form is validated and successfully submitted, the fields still show the text typed in by the user. I need them to be blank again after a successful submission. How do I do that?


This is how I keep the user input in the form. The unset attempt seems to have no effect and doesn't clean the input:
PHP Code:
<?php
 $formname 
htmlentities(stripslashes($_POST['name']));
 

 
// some more code including validation
 // if validation is successful then
 
$allgood “ok”;
 

 
// Unset attempt
 
if (isset($allgood)) {
 unset(
$formname);
 }
 
?>
 <form action="form.php" method="post" name="comment" id="captcha-form" >
 <input name="name" id="name" type="text" size="30" maxlength="20" value="<?php echo $formname?>" />
 *
 *
 *
 *
 </form>
__________________
THE FORCE is with me at last! All I need now is some TALKUPATION ;)
frofi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-27-2009, 04:01 PM Re: How to clean input and textarea fields
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
$formname="";
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-27-2009, 04:36 PM Re: How to clean input and textarea fields
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Quote:
Originally Posted by chrishirst View Post
$formname="";
I tried that already. It didn't work but I have realised in the meantime that my $allgood variable doesn't get set properly because my script can't really tell if all the conditions have been met all at the same time.

To remedy that, now every validator condition adds a value to an array. I need a script to check if there is an instance of “no” in the array. If there is none then the $allgood gets set to “ok” otherwise $allgood = “no”. I've figured out a way of doing it but as usual, it doesn't work. I'm just trying to create a working script. If I'm successful I'll post it here.

My array is called $data and here is the print_r output in case anyone wants to have a go:

Array ( [0] => no [1] => no [2] => yes [3] => no [4] => yes [5] => no [6] => yes [7] => no [8] => yes [9] => no )


This form is really giving me headache.
__________________
THE FORCE is with me at last! All I need now is some TALKUPATION ;)
frofi is offline
Reply With Quote
View Public Profile
 
Old 01-27-2009, 09:06 PM Re: How to clean input and textarea fields
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
I've got it! This is what I've done:
PHP Code:
<?php
   
if (in_array("no",$data)) {
         
$allgood false;
     } else {
         
$allgood true;
         }
 

 
$formname htmlentities(stripslashes($_POST['name']));
  
// same thing for all other input variables

  
if ($allgood == true) {
     
$formname "";
     
// same thing for all other input variables
  
}
 
?>
I had to place it between the form and the last validation part that was adding a value to the $data array. The placement was a major issue, which I didn't address before. I've altered my whole form so there is no validation PHP code in it. The CAPTCHA validation part of my form was inside the <form> tags and the $allgood value didn't make it further than the end of my script. On every validation failure, as the form got re-loaded, the $allgood lost it's value and the condition had no effect. Now all the fields are cleared if the form is successfully submitted.


Only took me half a day lol
__________________
THE FORCE is with me at last! All I need now is some TALKUPATION ;)
frofi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to clean input and textarea fields
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30241 seconds with 12 queries