businessman332211@hotmail.com Posted May 17, 2006 Share Posted May 17, 2006 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 More sharing options...
Jack McKalling Posted May 17, 2006 Share Posted May 17, 2006 (edited) 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 May 17, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
businessman332211@hotmail.com Posted May 17, 2006 Author Share Posted May 17, 2006 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 More sharing options...
justsomeguy Posted May 17, 2006 Share Posted May 17, 2006 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 More sharing options...
businessman332211@hotmail.com Posted May 17, 2006 Author Share Posted May 17, 2006 a lot of that makes sense, but I definitely like having the processor in an external page, I know it can be populater like that I just have to figure out how. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 17, 2006 Share Posted May 17, 2006 OK, well good luck. You will probably end up having to redirect to a URL with all of the form data URL-encoded and attached to the end of the address. Link to comment Share on other sites More sharing options...
businessman332211@hotmail.com Posted May 18, 2006 Author Share Posted May 18, 2006 I am playing around with it, and experimenting with it some, and I might have it on the same page, I know the javascript validation will be easier. Link to comment Share on other sites More sharing options...
deved Posted June 22, 2006 Share Posted June 22, 2006 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.<{POST_SNAPBACK}> 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 More sharing options...
justsomeguy Posted June 22, 2006 Share Posted June 22, 2006 Take a look at this:http://w3schools.invisionzone.com/index.php?showtopic=5344 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now