Privacy Policy

Community
Standards


Youth Tech's Online PHP Class: Lesson Three

Input [Chat: 8/2/02]

Hosted by YTCC Spark

Welcome back to PHP Class!  If you have any questions, as always, don't hesitate to email me.  Or, the preferred method, bring your questions to Chat, 10PM EST, every Friday!

Input

PHP has two very basic mechanisms for taking input.  (Actually, they are the same mechanism, used in two distinct manners.  PHP can either take input from an HTML Form, or from parameters passed on the end of the URL for the PHP document.

NOTE: I will not be offering anything more than discussion on HOW forms are used with PHP.  I am not teaching HTML forms here, if you aren't familiar with them, or would like a refresher, try this excellent tutorial.

Sample HTML Form With Explanation:

<FORM METHOD="POST" ACTION="your_php_doc.php">
<INPUT TYPE="hidden" name="website" value="mysite">
<INPUT NAME="name">
<INPUT TYPE="SUBMIT" VALUE="Go!" NAME="go">
</FORM>

<FORM METHOD="POST" ACTION="your_php_doc.php"> - ok, clearly, this line is where you change your_php_doc to the name of the PHP document that will handle input from the form.

<INPUT TYPE="hidden" name="website" value="mysite"> - Whenever this form is used, a variable named $website will be set to "mysite".  In fact, every input from a form generates a variable named $NAME_OF_INPUT set to the VALUE from the input.  (Whether provided by the form or the input from the user).

<INPUT NAME="name"> Will generate an input box where the user can type in free-response input.  Their input will be available in the variable $name in your PHP Document.

<INPUT TYPE="submit" VALUE="Go!" NAME="go"> - This creates the button you press to submit the form.  In this case, the variable $go is also set to "Go!".  You CAN have more than one submit button, with different values (or even different names, although that is not usually done).

The basic thing you should know when creating your HTML form and PHP script is that each INPUT from the FORM comes across as $NAME=VALUE.

Appending Input to the URL:

Sometimes you will see a web address like this:

email.php?to=ytccspark%40youthtech.com&from=webmaster%40youthtech.com

The script could be one used to send an automated email to the address listed after to=.

The variables would be available as $to and $from.  The ampersand (&) is used to seperate one variable from another.  The %40 is the "escaped" form of the "@" in an email address.  This method can either be used with a standard link (either written by the HTML designer or outputted from PHP) or with a form.  In a form, the only change required is to change the METHOD from "POST" to "GET".

Back to the Index

 

Copyright © 1996-2003, Youth Tech
Questions? Comments?