everisk Posted April 13, 2009 Share Posted April 13, 2009 Hi, I have a script where after form is submitted a series of check is done with PHP ( has to work with database so cannot check with javascript). If PHP found an error it should redirect back to the form and still keep the user entered value. How do I do that? My plan is just redirecting back with header:location but with this method, form value just got lost. Any help would be greatly appreciated. Thanks! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 13, 2009 Share Posted April 13, 2009 if you post back to the same script then its straight forward.. markup <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="username">Username</label> <input type="text" name="username" id="username" value="<?php echo $username;?>" /> <label for="password">Password</label> <input type="password" name="password" id="password" /> <input type="submit" name="login_bttn" id="login_bttn" value="Login" /> </form> the code that must come before... <?php $username = isset($_POST['username']) ? $_POST['username'] : null; .... ?> this means that when the form shows then $username has been initialized and will not error. if the form had been submitted and validation failed so we show the form again then $username will be set to what was previously submitted.... Quote Link to comment Share on other sites More sharing options...
everisk Posted April 13, 2009 Author Share Posted April 13, 2009 Thank you. Unfortunately I dont post to the same script but I guess I can use the same approach. Thanks! 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.