raydona Posted April 7, 2012 Share Posted April 7, 2012 Hi, I have a form in file A.php. <?php <form name="A.php" action="B.php" method="post"> ...... <input type="text" name="name" id="name" /> .... <input type="text" name="email" id="email" /> .... ?> When the form is submitted php validation takes place on form B.php <?php if ( isset($_POST['submitted']) { if ($_POST[name]) { $name = $_POST[name]; } else { //what code goes here? } ...... ?> What I would like to happen in the else statement is that if name field is left blank user is automatically redirected to A.php, the name field is highlighted and a small error message that the name field was left empty appears. How can that be achieved? I would be very grateful for all help. Link to comment https://forums.phpfreaks.com/topic/260486-redirecting-to-a-form-in-another-file/ Share on other sites More sharing options...
algidDes702 Posted April 7, 2012 Share Posted April 7, 2012 Is there a strong reason why you dont validate your form input on the same page? On A.php? for the action use "<?php echo $_SERVER["PHP_SELF"]; ?>" and include your isset validation in the top of your script. This is just one way to do it. algidDes702 Link to comment https://forums.phpfreaks.com/topic/260486-redirecting-to-a-form-in-another-file/#findComment-1335117 Share on other sites More sharing options...
Drummin Posted April 7, 2012 Share Posted April 7, 2012 I would agree that processing/validation should be done above <html> on the same page however I would use a empty action line in the form, eg. <form action="" method="post"> I WOULD NOT USE $_SERVER["PHP_SELF"] http://www.google.com/search?q=%24_SERVER%27PHP_SELF%27+xss+vulnerability&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a Link to comment https://forums.phpfreaks.com/topic/260486-redirecting-to-a-form-in-another-file/#findComment-1335121 Share on other sites More sharing options...
algidDes702 Posted April 7, 2012 Share Posted April 7, 2012 ahh interesting! i didnt know that, thank you for sharing Drummin! algidDes702 Link to comment https://forums.phpfreaks.com/topic/260486-redirecting-to-a-form-in-another-file/#findComment-1335245 Share on other sites More sharing options...
raydona Posted April 8, 2012 Author Share Posted April 8, 2012 Hi, Many thanks for the replies. Although I didn't include all the code, there is a lot of javascript in A.php to make the form appear stylish instead of the standard HTML inputs. That is why I wanted to keep the file separate from the php validation. I was wondering if I could write <form action="" method="post"> in A.php and include("A.php"); in B.php immediately below the php validation so that A.php appears immediately below the validation in B.php. But then how would I jump to input label? Link to comment https://forums.phpfreaks.com/topic/260486-redirecting-to-a-form-in-another-file/#findComment-1335398 Share on other sites More sharing options...
Drummin Posted April 8, 2012 Share Posted April 8, 2012 That should work, although I would normally include a processing page at the top of a display page above <html>, so B.php would be included to top of A.php. Link to comment https://forums.phpfreaks.com/topic/260486-redirecting-to-a-form-in-another-file/#findComment-1335403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.