Jump to content

php validation


Recommended Posts

look for advice/guidance/direction, on 2 subject.WHen I create a form I always validate it first with javascript very carefully. Then I validate it with php and then process it with php. Is it better for me to process it in php on the same page as the form, or on the same page as the processor. have like all the functions for validations first, and then the processor below that.The other thing I really needed help with,was what is the best way to get a form to repopulate itself. for instance if someone presses submit it normally refreshes, either by javascript or php when it validates to show the messages. I want it to repopulate all the values with what they already had in, I have a decent idea on how to do the text fields, but I can use a refresher, I am totally lost when it comes to check boxes, radio buttons and things like that, all the advice I can get will be greatly appreciated.

Link to comment
Share on other sites

I can help you with that, does this help you?

echo "<input type=\"radio\" name=\"something\" value=\"somevalue\" ",(@$_POST['something'] == "somevalue") ?"checked=\"checked\" " :"","/>";
echo "<input type=\"checkbox\" name=\"something2\" value=\"somevalue2\" ",(@$_POST['something2'] == "somevalue2") ?"checked=\"checked\" " :"","/>";
:) Edited by Dan The Prof
Link to comment
Share on other sites

Not really, as I am totally un familiar with teh checkboxes and radio buttons, I need to find out the theories behind how they are validated. But the main thing is whether I should validate the php on the same page as the form, or on the same page as the processor. And yes I do need to figure out how to repopulate the form fields as well, because I have no clue where to start with it.Thanks

Link to comment
Share on other sites

If you want to repopulate everything, you will want your form, validation, and processing all on one page. That way you don't have to make the form twice. You will want to use a hidden form variable to tell the page what to do when the form gets submitted:<input type="hidden" name="page_mode" value="process">When checkboxes get submitted to the server, if the checkbox is checked the server gets the value. So if you have this checkbox:<input type="checkbox" name="some_var" value="true">If someone checks this box and then submits, the server will receive a variable in $_POST called "some_var" with the value "true". If the checkbox is not checked, the server doesn't even receive the "some_var" variable. Radio buttons are similar.To have a checkbox or radio button be selected by default, you include "checked" in the tag:<input type="checkbox" name="some_var" value="true" checked>A select menu uses "selected" instead of "checked":<select name="dropdown"><option value="1">Option 1</option><option value="2" selected>Option 2</option></select>

Link to comment
Share on other sites

  • 1 month later...
look for advice/guidance/direction, on 2 subject.WHen I create a form I always validate it first with javascript very carefully.  Then I validate it with php and then process it with php.  Is it better for me to process it in php on the same page as the form, or on the same page as the processor.  have like all the functions for validations first, and then the processor below that.The other thing I really needed help with,was what is the best way to get a form to repopulate itself.  for instance if someone presses submit it normally refreshes, either by javascript or php when it validates to show the messages.  I want it to repopulate all the values with what they already had in, I have a decent idea on how to do the text fields, but I can use a refresher, I am totally lost when it comes to check boxes, radio buttons and things like that, all the advice I can get will be greatly appreciated.

You mention validating a form using PHP. Could you advise on how this is done, or point me in the right direction?
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
 Share

×
×
  • Create New...