Page 166 - Open Soource Technologies 304.indd
P. 166
Unit 9: Working with Forms
• PHP also works with an optional hidden field that can be inserted before the file upload Notes
field.
• The mail() function takes four parameters: The recipient, the subject, the message, and
any additional mail headers.
9.11 Keywords
FORM Elements: FORM elements The FORM element’s ACTION argument points to a file called
listing2.php, which processes the form information. The method of this form is POST, so the
variables are stored in the $_POST superglobal.
HTML and PHP Code on a Single Page: In some circumstances, you might want to include form
parsing code on the same page as a hard-coded HTML form. Such a combination can be useful
if you need to present the same form to the user more than once.
Hidden Fields to Save State: A hidden field behaves exactly the same as a text field, except
that the user cannot see it unless he views the HTML source of the document that contains it.
Sending Mail on Form Submission: This is the form that the submitter fills in; submitting this
form causes form-submit to email a message based on the information filled in here. This form
asks for the submitter’s name, email address, and some comments.
System Configuration for the mail() Function: The mail() function allows you to send emails
directly from a script.
Working with File Uploads: Information about the uploaded file becomes available to you in
the $_FILES superglobal, which is indexed by the name of the upload field (or fields) in the form.
File Upload Form: This field must be called MAX_FILE_SIZE and should have a value
representing the maximum size in bytes of the file that you’re willing to accept.
9.12 Self Assessment Questions
State True or False:
1. The Form elements action argument points to a file called listing 2.php.
( a) True (b) False
2. Form-passing code can be useful if you need to present the same form to the user more
than once.
( a) False (b) True
3. Functions can be called from within your HTML code and can be reused in other projects.
( a) True (b) False
4. Making no changes to php.ini on any platform, you must restart the web server process.
( a) True (b) False
Fill in the blanks:
1. Impart from the “products[] from elements created on line 14 is available in an array called
_________________.
LOVELY PROFESSIONAL UNIVERSITY 161