Hick
Hick

Reputation: 36404

How to collect data using php from an HTML form?

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 ?

Upvotes: 4

Views: 9235

Answers (4)

JP19
JP19

Reputation:

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"]; }

Upvotes: 2

Thariama
Thariama

Reputation: 50832

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>

Upvotes: 0

Chandresh M
Chandresh M

Reputation: 3828

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.

Upvotes: 2

Tyler Eaves
Tyler Eaves

Reputation: 13131

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

Upvotes: 1

Related Questions