Jump to content

About php and Forms


yaniv81

Recommended Posts

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...

Link to comment
Share on other sites

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 by Wickham
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...