PHP from, or PHP form?

27 April 2009

When first starting to learn PHP from online tutorials it, to me, was epic!

I started learning PHP from a site called www.tizag.com/phpT/ and found this really helpful.

Now, though, when I get an error or problem the tutorials aren't that much help and so I find my answers to my issues in PHP from forums.

PHP from is a very common misspelling of a PHP form.

If you did type "PHP from" instead of "PHP form" then you're in the right place...

PHP forms can have either a "post" or "get" method - which will depend on how the values can be received at the next page.

The "post" method will send the values, but hidden to the page's URL, whereas the "get" method will send the values in the URL using page.php?variable1=value1&variable2=value2 etc.

To decide which page the website directs the user to once they've clicked "submit" you will need to also define this at the top of the form using the "action" attribute.

An example of the top of a PHP form would be:
<form method="post" action="target_page" name="myform">

The only other attribute you may need to use when setting up the form would be "enctype", which defaults as "plain/text", but can also be used to send "multipart/form-data" or "application/x-www-form-urlencoded".

I've never personally used "application/x-www-form-urlencoded", but the "multipart/form-data" will be needed if you're uploading files when using the form.

Now building the form you will need <input> tags and maybe a <textarea> tag if you want to use some open text areas. Then close the form using </form>

On the target page you will need to use PHP to retrieve the values sent via the form on the previous page.

If it was a "post" method then use:
$variable1 = $_POST['variable1'];

Or if it was a "get" method then use:
$variable1 = $_GET['variable1'];

http://www.peternichol.com/entry/trackback/95/

Please leave a comment using the form provided.