user2201462
user2201462

Reputation: 1021

form action attribute set to?

When is the need to set from action attribute to ? like this

<head>
<title></title>
</head>
<body>
<form action="?" method="post">
<div>
<label for="joketext">Type your joke here:</label>
<textarea id="joketext" name="joketext" rows="3" cols="40"></textarea>
</div>
<div><input type="submit" value="Add"/></div>
</form>
</body>

Upvotes: 0

Views: 172

Answers (4)

Nikitas
Nikitas

Reputation: 1003

If you use:

<form action="myform.php" method="post">

Then the form redirects to myform.php And in this file there is the code that checks the form.

If you use:

<form action="myform.php?check" method="post">

Then the form redirects to myform.php but it also adds check to the $_GET array.

So you can write a piece of code that only works if there is a check element in your $_GET array.

if(isset($_GET['check']))
{
    // your code here
}

In PHP every element after ? is a member of the $_GET array For example: http://www.example.com?product_id=1&product_name=acme means that the $_GET array currenty has two elements:

product_id
product_name

Upvotes: 1

Rush
Rush

Reputation: 496

I guess the below link should help. http://www.w3schools.com/tags/att_form_action.asp

It allows you to specify where you want to post your form data

Upvotes: 0

Zeddy
Zeddy

Reputation: 2089

The need for setting the form action is so that the form can be submitted to whatever action you dictate, if you leave the action blank then the form will submit to itself (the same page it is on)

If you had a form handler which was not visible but handled all the processing, then you could define the handler address (url) in the form action or even send the data to another page if you so choose.

And wherever you sent it to, a form handler or itself or another page, that would take care of the data and deal with accordingly, as you so choose.

Upvotes: 1

Thomas Lai
Thomas Lai

Reputation: 895

when you want form data to be stored, you can set it to a php file and save the data to a database, text file, or xml.

Upvotes: -1

Related Questions