simpli Posted March 28, 2009 Share Posted March 28, 2009 Hi, I have a form that submits to itself for validation. I have the js validation that works fine but in case js is absent I have the server side validation set up. How could I ensure that after validation the form is showed with the fields it had so the user doesn't have to start over? I have radio buttons, input texts and select boxes in the mix. Thanks for pointing toward a solution. J-R Quote Link to comment Share on other sites More sharing options...
POG1 Posted March 28, 2009 Share Posted March 28, 2009 echo '<input value="'.$_REQUEST['username'].'" name="username" />'. '<select name="dropdown">'. '<option value="1" '.(($_REQUEST['dropdown'] == '1')?'selected="selected"':FALSE).'>1</option>'. '<option value="2" '.(($_REQUEST['dropdown'] == '1')?'selected="selected"':FALSE).'>2</option>'. '</select>'. '<input type="radio" name="rdo" '.(($_REQUEST['rdo'] == TRUE)?'checked="checked"':FALSE).'/>'; Quote Link to comment Share on other sites More sharing options...
KPH71 Posted March 28, 2009 Share Posted March 28, 2009 Another similar way that shows you where to put the validation etc. Post the information to the same page. Put an if statement at the top to check if the form is submitted and validate it in there. Then underneath have the form with if statements to echo the values of the forms if they were set. Quick e.g. with a few different types of inputs in the form: <?php if ($_POST['send']=="Send") { //validate here } ?> <form action="" method="post"> <input type="text" name="something" value="<?php if(isset($_POST['something'])){echo $_POST['something'];} ?>" /> <input type="radio" name="radiobutton" value="yes" <?php if($_POST['radiobutton']=="yes"){echo ' checked="checked" ';}?>/> <input type="radio" name="radiobutton" value="no" <?php if($_POST['radiobutton']=="no"){echo ' checked="checked" ';}?>/> <select name="test"> <option value="1"<?php if($_POST['test']=="1"){echo ' selected="selected" ';} ?>>1</option> <option value="2"<?php if($_POST['test']=="2"){echo ' selected="selected" ';} ?>>2</option> </select> </form> (Obviously you don't have to open and close the <?php ?> like I have - I did it to make it easier to understand) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.