nealios Posted March 18, 2008 Share Posted March 18, 2008 Hello,Im performing some php validation on a form, before it is entered into the database.It check the validity of the field in a separate insert script, it then relays the message back to the form if there is an error.The problem is when the error message relays the whole page is refreshed so the user loses any data previously entered.Is there a way to temporarily save the data if there is an error?example of validation error that checks to see if an email is valid.Code:if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $message15 = "Error: Please email is in the right format"; header("Location: newcustomer.php?message15=$message15"); exit(); } Link to comment Share on other sites More sharing options...
jeffman Posted March 18, 2008 Share Posted March 18, 2008 Sounds like an ideal case for AJAX. Or have you tried plugging that regex into a javascript statement? Obviously, it's up to you where you do the validating. Link to comment Share on other sites More sharing options...
nealios Posted March 18, 2008 Author Share Posted March 18, 2008 Sounds like an ideal case for AJAX. Or have you tried plugging that regex into a javascript statement? Obviously, it's up to you where you do the validating.Thanks for the reply, ive heard you can do it with Sessions but not sure how i would even start going about it! Link to comment Share on other sites More sharing options...
justsomeguy Posted March 18, 2008 Share Posted March 18, 2008 Sessions just store data. If you want to validate a variable with a PHP script without reloading the page then you can use AJAX to send that variable to PHP and get a response back. If you just want to repopulate the form if there was an error then you will need the form to check for previously entered values. You can use the session to store those values if you want, but it would be easier to just process the form in the same script where you display it. So you would have PHP code on the top of the script that checks if the form was submitted and processes it if so. Then you have the form lower down in the script that would check to see if there are values that it needs to enter into the fields. These can either be default values or previously entered values. There is a little bit of that going on in this tutorial:http://w3schools.invisionzone.com/index.ph...ost&p=96608 Link to comment Share on other sites More sharing options...
jeffman Posted March 18, 2008 Share Posted March 18, 2008 I think maybe we have not been as clear as possible. The AJAX solution means not having to refresh the page at all, so there will be no need to save data and then repopulate. It make your UI a lot friendlier. Link to comment Share on other sites More sharing options...
nealios Posted March 19, 2008 Author Share Posted March 19, 2008 I think maybe we have not been as clear as possible. The AJAX solution means not having to refresh the page at all, so there will be no need to save data and then repopulate. It make your UI a lot friendlier.Cheers guys, The tutorial worked a charm! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.