yaniv81 Posted January 27, 2011 Report Share Posted January 27, 2011 Hi, I'm really at the beginning of the php tutorials so it's really a basic question... when processing the forms in the videos you set the "action" of the form to a different php file, does it make any difference if I decide to set the "action" to the same file itself? I just find it much more useful... Quote Link to comment Share on other sites More sharing options...
Wickham Posted January 27, 2011 Report Share Posted January 27, 2011 (edited) You can do that but the PHP code becomes a bit more complicated. You have to get the order of processing correct. The page has to be coded so that the action is ignored at first while the form input boxes are empty, then after clicking the submit button the action processes the same page again starting from the top again and this time the code knows that the boxes have content so it processes the action. Here is an example http://www.wickham43.net/formphptomysql.php The PHP is coded before the form, but is ignored on the first pass and only processed on the second pass after submission. You won't see the PHP code in the online page source code but it is shown on the page. The form submits to a database but you could adapt for sending an email. Edited January 27, 2011 by Wickham Quote Link to comment Share on other sites More sharing options...
yaniv81 Posted January 27, 2011 Author Report Share Posted January 27, 2011 ok... so let say I want to set the action to a different file to process it, but want the user to stay in the same page and also print the results, is there a way to do that? I guess I can just use "include" to keep the code clean...but still I was wondering if such thing is possible? Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 27, 2011 Report Share Posted January 27, 2011 Yes, you could. You could redirect to a different file for processing, and then redirect back to the original form using the header() function. Quote Link to comment Share on other sites More sharing options...
yaniv81 Posted January 27, 2011 Author Report Share Posted January 27, 2011 great! thanks for your help 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.
Note: Your post will require moderator approval before it will be visible.