Deepzone Posted February 24, 2013 Share Posted February 24, 2013 Hi there, I use ACTION="xxx.php" in form tag to move to another page. Is it possible, in php, for me to remain on the same page if error occur else then post to xxx.php page? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/274886-conditional-post-to-another-php-page/ Share on other sites More sharing options...
AyKay47 Posted February 24, 2013 Share Posted February 24, 2013 With strictly PHP I do not believe this to be possible since the form handler would need to process the form before determining if any errors occurred. A better approach would be to handle both the form and any errors that occur on the landing page. Quote Link to comment https://forums.phpfreaks.com/topic/274886-conditional-post-to-another-php-page/#findComment-1414662 Share on other sites More sharing options...
daviddivine Posted February 24, 2013 Share Posted February 24, 2013 Uhmm... yes. Validate your form with Javascript/jQuery then submit the form (submit()) to the desired page if no error(s) was found. Quote Link to comment https://forums.phpfreaks.com/topic/274886-conditional-post-to-another-php-page/#findComment-1414667 Share on other sites More sharing options...
DavidAM Posted February 24, 2013 Share Posted February 24, 2013 Javascript validation is not reliable. The user may choose to turn off Javascript. The best approach (IMO) is to post to the same page and process the data. If an error occurs, you can show the form, with the user's supplied data so they don't have to re-type everything, just the invalid stuff. If there are no errors you can use PHP to redirect to the final page: header('Location: http://www.mydomain.com/thankyou.php'); exit(); Quote Link to comment https://forums.phpfreaks.com/topic/274886-conditional-post-to-another-php-page/#findComment-1414669 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.