简体   繁体   中英

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>

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.

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

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

当您要存储表单数据时,可以将其设置为php文件,然后将数据保存到数据库,文本文件或xml中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM