Home and Learn: PHP Programming Course

PHP and the Action Attribute of HTML Forms


The Action attribute is crucial. It means, "Where do you want the form sent?". If you miss it out, your form won't get sent anywhere. You can send the form data to another PHP script, the same PHP script, an email address, a CGI script, or any other form of script.

In PHP, a popular technique is to send the script to the same page that the form is on – send it to itself, in other words. We'll use that technique first, but you'll see both techniques in action.

So you need to change the form you have been creating in the previous sections, the one that should be called basicForm.php. Locate the following, and amend the ACTION line to this:

<Form Name ="form1" Method ="POST" ACTION = "basicForm.php">

So we're going to be sending the form data to exactly the same page as the one we have loaded – to itself. We'll put some PHP on the page to handle the form data. But for now, save your work again and then click your submit button. You won't see anything different, but you shouldn't see any error message either!

Once your script has an Action attribute set, you can then Submit it. Which we'll see in the next part.

<-- Back One Page | Move on to the Next Part -->

Back to the PHP Contents Page


Email us: enquiry at homeandlearn.co.uk