Home arrow Graphic Design arrow Page 8 - Using HTML Quickform for Form Processing
GRAPHIC DESIGN

Using HTML Quickform for Form Processing


With HTML_QuickForm version 3.1, you can have a consistent look across all your forms and a simplified file upload. This chapter starts with the basics then shows you how to process submitted form data with HTML_QuickForm. (From the book, Essential PHP Tools: Modules, Extensions, and Accelerators, by David Sklar, Apress, 2004, ISBN: 159059280.)

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 193
September 01, 2004
TABLE OF CONTENTS:
  1. · Using HTML Quickform for Form Processing
  2. · Steps for the Example
  3. · Individual Elements
  4. · Text, Password, Textarea
  5. · Hidden, Select
  6. · Checkbox, Radio
  7. · Submit, Reset, Button, Image
  8. · File, advcheckbox, Static
  9. · Header, Link, HTML
  10. · Element Groups
  11. · Processing Submitted Data
  12. · Without a Callback Function
  13. · Setting Validation Rules

print this article
SEARCH DEVARTICLES

Using HTML Quickform for Form Processing - File, advcheckbox, Static
(Page 8 of 13 )

 

File

The file element produces an HTML <input type="file"> tag. This displays a text box and a button that, when clicked, brings up a file selection dialog box. The file element lets users upload a file to your server.

These are the valid arguments when creating a file element:

  • $elementName: The name attribute of the element’s <input> tag

  • $elementLabel: The label of the element in the form

  • $attributes: Arbitrary element attributes, as a string or an associative array

It takes the following methods:

  • setSize(): Sets the size attribute, which controls how wide the input field is in the browser

  • getSize(): Gets the value of the size attribute

The following is the sample usage:

$form->addElement('file','data','Your File:');

The following is the sample HTML:

<tr>

<td align="right" valign="top"<<b>Your File:</b></td>

<td valign="top" align="left"<<input name="data" type="file" /></td>

</tr>

When your form contains a file element, HTML_QuickForm adds an enctype attribute with the value multipart/form-data to the <form> tag. This instructs the browser to properly package the submitted form data, including the contents of the uploaded file, so that the server can parse it. Additionally, HTML_QuickForm adds a hidden element called MAX_FILE_SIZE to the form. This defaults to 1MB (1,048,576 bytes). You can change this by calling the setMaxFileSize() method on the form object with a new value. The MAX_FILE_SIZE variable is used by well-behaved browsers to prevent uploads of too-large files. A malicious user could circumvent the MAX_FILE_SIZE limitation. The maximum uploaded file size that PHP accepts is controlled by PHP’s upload_max_filesize configuration directive.

advcheckbox

The advcheckbox element generates a checkbox with a value that you can specify. This differs from the checkbox element, whose value attribute is always set to 1. The advcheckbox element creates a regular checkbox element in the form but also a hidden element. When the checkbox is checked, the value of the hidden element is updated, using JavaScript, to the specified value.

These are the valid arguments when creating an advcheckbox element:

  • $elementName: The name for HTML_QuickForm’s internal element array

  • $elementLabel: The label of the text in the form

  • $text: The text to display in the form

  • $attributes:Arbitrary element attributes, as a string or an associative array

  • $values: The specified value to submit when the checkbox is checked It takes the following method:

  • setValues(): This sets the values stored in the hidden element. You can pass a false value to setValues() to make the checkbox act like a regular check-box. Otherwise, the number or string passed in is stored in the hidden element.

The following is the sample usage:

$form->addElement('advcheckbox','window_seat','Seat Location:', 'Check if you want a window seat',null,'yes');

The following is the sample HTML:

<tr>
<td align="right" valign="top"><b>Seat Location:</b></td>
<td valign="top" align="left"><input name="__window_seat"
type="checkbox" value="1" onclick="if (this.checked) {
this.form['window_seat'].value='yes'; }else { this.form['window_seat'].value='';
}" />Check if you want a window seat<input type="hidden" name="window_seat"
value="" /></td>
</tr>

static

The static element generates plain text that is paired with a label in the form layout. This element isn’t a form widget like a text box or select menu but is useful for displaying information about or a description of a neighboring element.

These are the valid arguments when creating a static element:

  • $elementName: The name for HTML_QuickForm’s internal element array

  • $elementLabel: The label of the text in the form

  • $text: The text to display in the form

  • $attributes:Arbitrary element attributes, as a string or an associative array

The following is the sample usage:

$form->addElement('static','info','Information:',"Don't run with scissors");

This is the sample HTML:

<tr>
  <td align="right" valign="top"<<b>Information:</b></td>
  <td valign="top" align="left">Don't run with scissors</td>
</tr>

This chapter is from Essential PHP Tools: Modules, Extensions, and Accelerators, by David Sklar, (Apress, 2004, ISBN: 1590592808). Check it out at your favorite bookstore today.

Buy this book now.


blog comments powered by Disqus
GRAPHIC DESIGN ARTICLES

- Customizing Wordpress Favicons and Gravatars
- Building Corner Effects with Transparent Bac...
- 3D Graphics Technology: VRML Part I - Introd...
- Creating Visual Effects
- Web Page Design Overview
- Creating Artistic Photographs
- Working with Tools in Paint Shop Pro 8
- Using HTML Quickform for Form Processing
- Introduction to Adobe FrameMaker
- WebLogic Workshop, WebLogic Platform, and th...
- Planning the Site
- Working with Web Services
- WebLogic Workshop Application Development Ba...
- Scanning Images for Web Use
- Web Graphics Overview

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials