Jump to content

filling a form


jimfog

Recommended Posts

I have a form in which some fields will be displayed only if the user chooses a specific optionfrom 2 radio buttons.These form fields are set to display="none" and I use javascript to make them visible. I have also made a function where it checks if the user has filled in the fields. And here comes the problem. The function checks all the fields, even of the ones that are set to display, none. That said,if the user fills in all the fields required for a specific option chosen(in which option the fields set to display none stay hidden from view), still, the function that checks if the fields are filled outputs false-so, modifications are required,what do you propose? here is the function and beneath it is the form:

 function filled_out($post){		  $wasFilledOutCompletely = true;		  // test that each key has a non empty string value		  foreach ($post as $key => $value) {				 if ($value == '') {						$wasFilledOutCompletely =  false;				 }		  }  return $wasFilledOutCompletely;   }

<form action="register_form.php" method="post"> <input name="username/e-mail" placeholder="Username/e-mail" type="text" size="40" /><br> <input type="radio" name="usertype" value="0"> End user<br> <input type="radio" name="usertype" value="1"> Business user<br> <select style="display:none;" name="usertype"> <option value="1">test1</option> <option value="2">test2</option> <option value="3">test3</option> <option value="4">test4</option> </select> <input style="display:none;" name="name" placeholder=Name" type="text" size="40" /><br> <input style="display:none;" name="lastname" placeholder="lastname"type="text" size="40" /><br> <input name="password" placeholder="Password"type="text" size="40" /><br> <input name="passwordretyped" placeholder="Password...again" type="text" size="40" /><br> <fieldset class="formset"><input name="submit" type="submit" /></form> Do you think maybe a I should write 2 functions, one for all the fields(visible and non-visible) and one for the visible only. One function for each registration scenario?

Edited by jimfog
Link to comment
Share on other sites

change
<form action="register_form.php" method="post">

to

<form action="register_form.php" method="GET">

and get variable you need in address bar after complete change it back

I did not quite understand the last phrase after..."complete change it back". Do you mean, to convert the GET variables to POST? And something else...I do not think it is good from a securitypoint of view to pass registration variables in a GET array-these must always be hidden, so the POST method is preferred here.
Link to comment
Share on other sites

I am going to do something else after all.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...