HTML Action attribute and PHP

Form ACTION attribute with PHP

In php when we submit the form the form where should be sent it depend on Action attribute.
The Action attribute is used to give link to another form.
We can send the form data to another PHP script page, or the same PHP page or any other form or script.

If we send the form data on same page or we can say send data to itself, then we have to define proper Action attribute for it.

Here we have two way for sending data one is send data to itself and other one is send data to another PHP script.


lets start with first method send data to same page.

In previous php script firstexample.php write ACTION=”” attribute like:

<FORM name=”form1″ action=”firstexample.php” method=”GET”>

Here we set the action=”firstexample.php” means the data send to itself or we can say data send to same page when page loaded.

When run above script the page send textbox information to same page as we write the same page name in action attribute.

If we wan to handle the data which is submitted to form then we have to do some PHP programming.

PHP Example to get form data on same page.

The PHP script out put is:

HTML Action attribute and PHP

HTML Action attribute and PHP

Above PHP script we use GET method to send data and we write some PHP script in head tag for display name on web form.
we write here action=firstexample.php” same script name so we write PHP script on same page for handle submitted data.


Now lets learn how to send data to another PHP script page.

For send data to another PHP form, first create another php script file with result.php name.
Here we write PHP script code on result.php page. We send the data to result.php script.

write Action attribute like:

<FORM name=”form1″ action=”result.php” method=”GET”>

Example of send data to another form in php.

create result.php page with below php code:

When we run the script it should look like:

HTML Action attribute and PHP

HTML Action attribute and PHP

In above php example we enter username in form firstexample.php ¬†and click login button then the username will displayed on second result.php page. In this example we set action=”result.php” in form tag.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + 6 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">