ckrudelux Posted August 12, 2011 Share Posted August 12, 2011 How do you do then sending messages to the user then some input fields are missing then submiting.Js stoping them from sending.cookies, get, submit script on the same page?Looking for insperation. Link to comment Share on other sites More sharing options...
Man In Tan Posted August 12, 2011 Share Posted August 12, 2011 I used to redirect back to the form, with an extra $_GET value in the URL, to tell the page which error message to display, but the problem with that is that you can't auto-refill the values the user already entered.A better way would be to do it would be to require() the page with the form after setting an $error value. On the form page, check to see if $error is set with isset(), and if it is, display the correct error message. Link to comment Share on other sites More sharing options...
thescientist Posted August 12, 2011 Share Posted August 12, 2011 I used to redirect back to the form, with an extra $_GET value in the URL, to tell the page which error message to display, but the problem with that is that you can't auto-refill the values the user already entered.A better way would be to do it would be to require() the page with the form after setting an $error value. On the form page, check to see if $error is set with isset(), and if it is, display the correct error message.if you submit the form to itself, the $_GET/$_POST variables will be available to the page. for a truly responsive form, I would have basic JS validation per 'important' form field doing validation onblur. I would also validate the form before allowing the submit event to go all the way through. Have the form redirect to itself, and it will pass all the form values 'back' to itself. From there, you can do any server side validation you need before sending the data where you want it to go. If there are any problems, you are still on the form page so you can re-populate the form fields with the user inputted data. Or, if everything clears and the form submission was successful, you can either prevent the form from displaying and display a success message, or redirect them to a success page. Link to comment Share on other sites More sharing options...
ckrudelux Posted August 12, 2011 Author Share Posted August 12, 2011 if you submit the form to itself, the $_GET/$_POST variables will be available to the page. for a truly responsive form, I would have basic JS validation per 'important' form field doing validation onblur. I would also validate the form before allowing the submit event to go all the way through. Have the form redirect to itself, and it will pass all the form values 'back' to itself. From there, you can do any server side validation you need before sending the data where you want it to go. If there are any problems, you are still on the form page so you can re-populate the form fields with the user inputted data. Or, if everything clears and the form submission was successful, you can either prevent the form from displaying and display a success message, or redirect them to a success page.Kind of what I was thinking about... but are there others known methods trying to get a picture of what my options are. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 12, 2011 Share Posted August 12, 2011 You can also submit the entire form through ajax and handle the response with Javascript. Link to comment Share on other sites More sharing options...
ckrudelux Posted August 12, 2011 Author Share Posted August 12, 2011 You can also submit the entire form through ajax and handle the response with Javascript.Yeah.. but what would still need a backup plan for none js users. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2011 Share Posted August 13, 2011 Right, if Javascript wasn't enabled then the onsubmit handler wouldn't execute and the form would submit normally. Link to comment Share on other sites More sharing options...
zamight Posted August 15, 2011 Share Posted August 15, 2011 <?phpIf(empty($_POST['username']) OR empty($_POST['password']))Header("Location: login.php?error=1"); die();?><?phpif($_GET['error']){// show empty msg}?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.