开发者

How to collect data using php from an HTML form?

开发者 https://www.devze.com 2023-01-30 01:04 出处:网络
Suppose there is a HTML file that has a form in it , which contains some data , which have been taken input from the user using textarea and checkbox . How do I send this data across to a PHP file开发

Suppose there is a HTML file that has a form in it , which contains some data , which have been taken input from the user using textarea and checkbox . How do I send this data across to a PHP file开发者_运维知识库 ?


you can post this data by submitting form and then on the php file you can use $_POST['fieldname']; for using value what you have on HTML page.


All form variables will be in $_GET or $_POST array in php (depending on which method you use to submit the form.

The textarea or checkbox need to be named like this:

<!-- HTML form -->

<form method="post" action="collect.php">
Comments: <textarea name="comments" cols="20" rows="5"></textarea> <br/>
Tick to select <input type="checkbox" name="checker"/> 
</form>



// collect.php    
$comments=""; if(isset($_POST["comments"])) { $comments = $_POST["comments"]; }
$checker=""; if(isset($_POST["checker"])) { $comments = $_POST["checker"]; }


The values from the form will be available in either, the $_GET and $_POST arrays, depending on the method used in the form.


The action attribute of a form defines the php script (or other script) the form data gets send to. You will be able to get the data using $_GET and $_POST. In the following example the text inputs will get submitted to form_action.php

<form action="form_action.php" method="get">
  First name: <input type="text" name="fname" /><br />
  Last name: <input type="text" name="lname" /><br />
  <input type="submit" value="Submit" />
</form>
0

精彩评论

暂无评论...
验证码 换一张
取 消