PHP DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to PHP Subscribe to Newsletters

PHP Form Handling

by David Sklar,author of Learning PHP 5
08/26/2004
Add Tag Clouds to Your Site

If your PHP program is a dynamic web page (and it probably is) and your PHP program is dealing with user input (and it probably is), then you need to work with HTML forms. Here are some tips for simplifying, securing, and organizing your form-handling PHP code.

1. Use $_SERVER['PHP_SELF'] as a form action.

The $_SERVER auto-global array holds various useful server- and request-specific info. The PHP_SELF element of $_SERVER holds the filename of the currently executing script (relative to your web site's document root directory). So, supplying $_SERVER['PHP_SELF'] as the action attribute of the form tag makes the form submit to the same page that displayed it. This lets you put the logic to handle the form in the same page as the logic that displays it. For many simple forms, this keeps things easy to manage.

2. Put [] at the end of the name of a multivalued form parameter.

When you've got a form element like <select multiple> that can submit multiple values to the server, put [] at the end of the form element name so that the PHP interpreter knows to accept multiple values.

For example, consider this form:

<form method="POST"  action="<?php echo $_SERVER['PHP_SELF']; ?>">
Pick some desserts: <select name="sweet[]" multiple>
<option value="puff"> Sesame Seed Puff</option>
<option value="square"> Coconut Milk Gelatin Square</option>
<option value="cake"> Brown Sugar Cake</option>
<option value="ricemeat"> Sweet Rice and Meat</option>
</select>
<input type="submit" name="Order">
</form>

If you pick Sesame Seed Puff and Brown Sugar Cake and submit the form, then $_POST['sweet'] is itself an array. $_POST['sweet'][0] is puff and $_POST['sweet'][1] is cake. That's because the name attribute of the <select> element is sweet[]. If the name was just sweet, then $_POST['sweet'] would be a string, holding only one of the selected values.

3. Test for form submission with a hidden element.

Include a hidden variable named, say, _submit_check in your forms like this:

<input type="hidden" name="_submit_check" value="1"/> 

Then, to test whether the form has been submitted, look for the _submit_check element in $_POST:

if (array_key_exists('_submit_check', $_POST)) {
     /* ... do something with the form parameters ... */
}

Testing for the presence of a hidden element avoids problems that can result from browsers' varying behaviors when a user submits a form by pressing the Enter key instead of clicking a submit button.

4. Divide your form handling into three parts: showing, validating, and processing.

Logically, the life cycle of a web form usually comprises three steps: showing the form, validating the submitted form parameters, and then processing the submitted form parameters to generate appropriate output.

Dedicate a function to each of these steps: showing, validating, and processing. With this modular design, deciding when each step needs to happen is straightforward.

On many pages, the logical flow goes like this:

  • If the request isn't a form submission, show the form.
  • If the request is a form submission, validate the submitted parameters.
  • If the submitted parameters are valid, process them.
  • If the submitted parameters are invalid, show the form.

With a function-based structure, the code to accomplish this looks something like:

if (array_key_exists('_submit_check',$_POST)) {
     // If validate_form() returns errors, pass them to show_form()
     if ($form_errors = validate_form()) {
         show_form($form_errors);
     } else {
         // The submitted data is valid, so process it
         process_form();
     }
} else {
     // The form wasn't submitted, so display
     show_form();
}

The page either displays the form (possibly with error messages) or displays the results of processing the form.

On other pages, particularly search pages, the logical flow goes like this instead:

  • If the request is a form submission, validate the submitted parameters.
  • Display the form.
  • If the request is a form submission, process the submitted parameters.

With a function-based structure, the code to accomplish this looks something like:

// Check for errors if the form was submitted
$form_errors = array_key_exists('_submit_check',$_POST) ?
                validate_form() : null;

// Always display the form
show_form($form_errors);

// Display results if the form was submitted
if (array_key_exists('_submit_check', $_POST)) {
     process_form();
}

Displaying the form above the processing output is useful for pages where users might want to adjust the form parameters based on the results. For example, if a product search for toasters that cost between $150 and $300 reveals only two choices, a user can adjust the price range and resubmit the form for a new search without going to a separate page.

5. Validate numbers with strval() and intval() or floatval().

Usually, the ability to switch a variable smoothly between holding a string or a number is a great convenience in your PHP programs. However, that makes form validation a little harder. To check whether a submitted form parameter is a valid integer, use strval() and intval() together like this:

if ($_POST['age'] != strval(intval($_POST['age'])) {
     $errors[] = 'Please enter a valid age.';
}

If $_POST['age'] isn't an integer, then intval() changes its value to something else. Adding strval() to the mix ensures that the comparison using the != operator doesn't do any silent, behind-the-scenes conversion.

Similarly, to check whether a submitted form parameter is a valid floating-point number, use floatval() instead of intval():

if ($_POST['price'] != strval(floatval($_POST['price']))) {
     $errors[] = 'Please enter a valid price.';
}

6. Entity-escape form data before printing it.

Printing data that comes from an external source (like form input) without properly encoding it leaves you vulnerable to the common, devastating, and embarrassing "cross-site scripting attack."

Pass external data through htmlentities() before printing it, like this:

print "Your monkey's name is: " . 
htmlentities($_POST['monkey_name']); 

Read more about cross-site scripting at http://www.owasp.org/documentation/topten/a4.html.

7. Print form elements' defaults with helper functions.

Printing out appropriate HTML for individual form elements is boring and repetitive. Fortunately, computers are quite good at boring and repetitive tasks. Encapsulate logic for printing HTML form elements in functions. Then, call those functions whenever you need to print a form element. Chapter 6 of Learning PHP 5 includes functions for a number of form elements. Here are a few samples:

// print a single-line text box
function input_text($element_name, $values) {
     print '<input type="text" name="' . $element_name .'" value="';
     print htmlentities($values[$element_name]) . '">';
}

//print a textarea
function input_textarea($element_name, $values) {
     print '<textarea name="' . $element_name .'">';
     print htmlentities($values[$element_name]) . '</textarea>';
}

//print a radio button or checkbox
function input_radiocheck($type, $element_name,
                           $values, $element_value) {
     print '<input type="' . $type . '" name="' .
           $element_name .'" value="' . $element_value . '" ';
     if ($element_value == $values[$element_name]) {
         print ' checked="checked"';
     }
     print '/>';
}

//print a submit button
function input_submit($element_name, $label) {
     print '<input type="submit" name="' . $element_name .'" value="';
     print htmlentities($label) .'"/>';
}

These functions are called like this:

print '<form method="POST" action=" . $_SERVER['PHP_SELF'] . '">';
print 'Name: '; input_text('name', $_POST);
print '<br/>';
print 'Description: ';
input_textarea('description', $_POST);
print '<br/>';
print 'Advanced?';
input_radiocheck('check','editor', $_POST, 'yes');
print '<br/>';
print 'Size: Big ';
input_radiocheck('radio','size', $_POST, 'big');
print ' Small ';
input_radiocheck('radio','size', $_POST, 'small');
print '<br/>';
input_submit('submit', 'Save');

The functions are easily extendable to add your own layout or support for arbitrary attributes for each element.

8. Investigate HTML_QuickForm for advanced form processing.

For more advanced form handling, check out the PEAR module HTML_QuickForm. It provides methods for the flexible and structured creation, validation, and display of HTML forms. HTML_QuickForm frees you from doing the grunt work of displaying defaults for form elements, encoding HTML entities, and duplicating validation code. Its built-in layout engine is customizable, and you can integrate with template engines like Smarty.

David Sklar is an independent consultant in New York City, the author of O'Reilly's Learning PHP 5, and a coauthor of PHP Cookbook.


In June 2004, O'Reilly Media, Inc., released Learning PHP 5.

  • Sample Chapter 8, "Remembering Users with Cookies and Sessions," is available free online.

  • You can also look at the Table of Contents, the Index, and the full description of the book.

  • For more information, or to order the book, click here.

Building Tag Clouds in Perl and PHP

Essential Reading

Building Tag Clouds in Perl and PHP
By Jim Bumgardner

Tag clouds are everywhere on the web these days. First popularized by the web sites Flickr, Technorati, and del.icio.us, these amorphous clumps of words now appear on a slew of web sites as visual evidence of their membership in the elite corps of "Web 2.0." This PDF analyzes what is and isn't a tag cloud, offers design tips for using them effectively, and then goes on to show how to collect tags and display them in the tag cloud format. Scripts are provided in Perl and PHP.

Yes, some have said tag clouds are a fad. But as you will see, tag clouds, when used properly, have real merits. More importantly, the skills you learn in making your own tag clouds enable you to make other interesting kinds of interfaces that will outlast the mercurial fads of this year or the next.


Read Online--Safari
Search this book on Safari:
 

Code Fragments only

Return to the PHP DevCenter


Questions for David? Ask them here.
You must be logged in to the O'Reilly Network to post a talkback.
Post Comment
Main Topics Oldest First

Showing messages 1 through 28 of 28.

  • PHP
    2009-05-08 09:46:25  UTHUMI [Reply | View]

    HI
    I AM RAM
    i BEGINER.
    <body>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" target="_blank" >

    First Name :<input type="text" size="12" maxlength="12" name="Fname">

    Last Name :<input type="text" size="12" maxlength="36" name="Lname">

    Gender ::

    Male :<input type="radio" value="Male" name="gender">

    Female :<input type="radio" value="Female" name="gender">

    Please choose type of residence::

    Steak :<input type="checkbox" value="Steak" name="food[]">

    Pizza :<input type="checkbox" value="Pizza" name="food[]">

    Chicken :<input type="checkbox" value="Chicken" name="food[]">

    <textarea rows="5" cols="20" name="quote" wrap="physical">Enter your favorite quote!</textarea>

    Select a Level of Education:

    <select name= "education">
    <option value= "Jr.High" selected>Jr.High</option>
    <option value="HighSchool">HighSchool</option>
    <option value="College">College</option></select>:

    Select your favorite time of day::

    <select name="TofD" size="3">
    <option value="Morning">Morning</option>
    <option value="Day">Day</option>
    <option value="Night">Night</option></select>:

    <input type="submit" value="submit" name="send">

    </form>
    </body>
    <?php
    if(isset($_POST['send']))
    {
    echo "Accessing Firstname : " . $_POST['Fname'] . "<br>";
    echo "Accessing Lastname : " . $_POST['Lname'] . "
    ";

    echo "gender " . $_POST ['gender']. "
    ";
    echo "food " . $_POST ['food']. "
    ";
    echo "education " . $_POST ['education']. "
    ";
    echo "TofD" . $_POST ['TofD']. "
    ";
    echo "quote" . $_POST ['quote']. "
    ";

    }
    ?>
    IF RUN THIS PAGE BUT I GOT THIS
    http://localhost/FORMS/<?php%20echo%20$_SERVER['PHP_SELF'];?>
    (HTTP Error 403 - Forbidden )
    PLS HELP ME...
    THANK U
  • PHP
    2009-05-08 09:46:14  UTHUMI [Reply | View]

    HI
    I AM RAM
    i BEGINER.
    <body>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" target="_blank" >

    First Name :<input type="text" size="12" maxlength="12" name="Fname">

    Last Name :<input type="text" size="12" maxlength="36" name="Lname">

    Gender ::

    Male :<input type="radio" value="Male" name="gender">

    Female :<input type="radio" value="Female" name="gender">

    Please choose type of residence::

    Steak :<input type="checkbox" value="Steak" name="food[]">

    Pizza :<input type="checkbox" value="Pizza" name="food[]">

    Chicken :<input type="checkbox" value="Chicken" name="food[]">

    <textarea rows="5" cols="20" name="quote" wrap="physical">Enter your favorite quote!</textarea>

    Select a Level of Education:

    <select name= "education">
    <option value= "Jr.High" selected>Jr.High</option>
    <option value="HighSchool">HighSchool</option>
    <option value="College">College</option></select>:

    Select your favorite time of day::

    <select name="TofD" size="3">
    <option value="Morning">Morning</option>
    <option value="Day">Day</option>
    <option value="Night">Night</option></select>:

    <input type="submit" value="submit" name="send">

    </form>
    </body>
    <?php
    if(isset($_POST['send']))
    {
    echo "Accessing Firstname : " . $_POST['Fname'] . "<br>";
    echo "Accessing Lastname : " . $_POST['Lname'] . "
    ";

    echo "gender " . $_POST ['gender']. "
    ";
    echo "food " . $_POST ['food']. "
    ";
    echo "education " . $_POST ['education']. "
    ";
    echo "TofD" . $_POST ['TofD']. "
    ";
    echo "quote" . $_POST ['quote']. "
    ";

    }
    ?>
    IF RUN THIS PAGE BUT I GOT THIS
    http://localhost/FORMS/<?php%20echo%20$_SERVER['PHP_SELF'];?>
    (HTTP Error 403 - Forbidden )
    PLS HELP ME...
    THANK U
  • php processing form
    2008-06-10 07:35:00  slainte_va [Reply | View]

    I have no php experience and I've been given the task of updating an input php form and a process form to send values to a database. Here is my problem. I can open the input php form no problem. This form then calls a process php file with method=post. However, when I try to read this process php file, it is blank with only an hmtl header at the top. I looked at another set of php forms and process php form and this one shows half of the code. It literally starts in the middle of variable: Q_CMD'];

    What do I need to do in order to view the entire file? Is it being stripped out somehow? I would appreciate any help on this.
    Thanks!
  • Display selected value in radio buttons when previous button is clicked
    2008-04-24 12:30:38  radice [Reply | View]

    Hello

    I have created some evaluation pages. It is one page when i am keeping track of question and displaying the question when next and previous is clicked. I have a problem of displaying the previously selected values in the radio buttons when going back and forward. Here is the code i used.

    function displayQuestionOne() {
    $answer = $_SESSION['answerArray'][0];
    echo "Answer".$answer;
    $choice1 = $choice2 = $choice3 = $choice4 = '';
    if ($answer == "Opens") $choice1='checked';
    if ($answer == "Opened") $choice2='checked';
    if ($answer == "Open") $choice3='checked';
    if ($answer == "will opened") $choice4='checked';

    ?>
    <tr>
    <td colspan="3">

    Select the correct answer

    </td>
    <td width="13%"> </td>
    </tr>
    <tr>
    <td width="7%">1.</td>
    <td colspan="2">Sample Question 1</td>
    <td> </td>
    </tr>
    <tr>
    <td> </td>
    <td colspan="2">


    <input type="radio" name="Question" value="Opens" <? $choice1 ?> /> Opens

    <input type="radio" name="Question" value="Opened" /> Opened

    <input type="radio" name="Question" value="Open" /> Open

    <input type="radio" name="Question" value="will opened" /> will opened

    </td>
    <td> </td>
    </tr>
    <?

    }

    ?>


    Any help is appreciated.

    Thanks
    Radice
  • form redirect doesn't seem to work
    2008-04-18 07:11:49  nutronstar [Reply | View]

    Your solution of putting the script for

    processing the form into the form document

    itself. The form tag should be:


    <form method="post" action=</p>

    "<?php echo $_SERVER['PHP_SELF']; ?>".

    This solution does not work because the URL


    becomes gibberish:


    http://../


    %3C?php%20echo%20$_SERVER['PHP_SELF'];%20?%3E.


    Tell me what the problem is. Thank you.

  • form redirect doesn't seem to work
    2008-04-18 07:11:34  nutronstar [Reply | View]

    Your solution of putting the script for

    processing the form into the form document

    itself. The form tag should be:


    <form method="post" action=</p>

    "<?php echo $_SERVER['PHP_SELF']; ?>".

    This solution does not work because the URL


    becomes gibberish:


    http://../


    %3C?php%20echo%20$_SERVER['PHP_SELF'];%20?%3E.


    Tell me what the problem is. Thank you.

  • php and php session management
    2007-12-12 23:41:11  martika [Reply | View]

    got this question: using php and php session management, create a web page that allows users to selct the background colour and font size. these attributes should be remembered and used when the page is displayed, so that when the user revisits the page during the same browser session, the page is displayed using the colour and font attributes remembered for the user.
  • Got it
    2007-10-29 07:37:27  jblifesetyles [Reply | View]

    You have to use $_POST['variable'] as $variable has been reset on page load
  • Multiple Forms On One PHP Page
    2007-10-28 19:44:32  jblifesetyles [Reply | View]

    Sorry about the multiple posts... didn't think it went because I wasn't a verified member yet..

    also, with the formatting..

    I have a <!-- <p align="center"> -->

    before the submit button, and for some reason, it picked it up, despite being inside of the <!-- <code> -->
  • Multiple Forms On One PHP Page
    2007-10-28 19:41:01  jblifesetyles [Reply | View]

    Hi all... first, thanks in advance for the help.

    I have a php page with 2 forms one for creating a country, and another for creating a liason. The liason has to be assigned to a country that has been created in the first form.

    I get the form to load and everything, but it keeps posting blank rows back to the database. I'm a relative newb, hence the probably simple solution.

    Here's the full code for my form(s)


    <?php

    /* Make sure we have admin rights */

    require_once('admin-header.php');
    require_once('admin.php');

    if (!current_user_can('edit_users') )
    wp_die(__('Cheatin’ uh?'));

    /* Posting to Countries */

    if (array_key_exists('gl_country_submit', $_POST)) {
    $addcountry = "INSERT INTO gl_countries VALUES('$country_id','$country_name','$flag_url','$thumb_url')";

    mysql_query($addcountry);

    print_r($addcountry);
    }

    /* Posting to Liasons */

    if (array_key_exists('gl_liason_submit', $_POST)) {
    $addliason = "INSERT INTO gl_liasons VALUES('$liason_id','$country_id2','$liason_firstname','$liason_lastname','$organization','$email','$site_url','$img_url','$address1','$address2','$address3','$phone','$notes')";

    mysql_query($addliason);

    print_r($addliason);
    }

    ?>

    <!-- Form to add a country -->

    <div class="wrap">
    <h2>Add Country</h2>
    <form method="post" action="<?php echo $PHP_SELF;?>">
    <input type="hidden" name="country_id" value="null">
    <table>
    <tr>
    <td align="left">Country</td>
    <td><input type="text" name="country_name"></td>
    </tr>
    <tr>
    <td align="left">Flag URL</td>
    <td><input type="url" name="flag_url"></td>
    </tr>
    <tr>
    <td align="left">Flag Thumbnail URL</td>
    <td><input type="url" name="thumb_url"></td>
    </tr>
    <tr>
    <td colspan="4">


    <input type="submit" value="Add Country" name="country_submit"></td>
    </tr>
    <input type="hidden" name="_submit_check_country" value="1"/>
    <input type="hidden" name="gl_country_submit" value="process">
    </table>
    </form>

    <?php
    if (array_key_exists('_submit_check_country', $_POST)) {
    echo("<?php $country_name?> is now svailable for Liasons!");
    }
    ?>
    </div>

    <!-- Form to add a liason -->

    <div class="wrap">
    <h2>Add Liason</h2>
    <form method="post" action="<?php echo $PHP_SELF;?>" >
    <input type="hidden" name="liason_id" value="null">
    <table>
    <tr>
    <td align="left">Country</td>
    <td><?php
    $query = "SELECT * FROM gl_countries";
    $results = mysql_query($query);
    echo '<select name="country_id">';
    while ($thisrow = mysql_fetch_array($results))
    {
    echo '<option value="'.$thisrow['country_id2'].'">'.$thisrow['country_name'].'</option>';
    }
    echo '</select>';?></td>
    </tr>
    <tr>
    <td align="left">First Name</td>
    <td><input type="text" name="liason_firstname"></td>
    </tr>
    <tr>
    <td align="left">Last Name</td>
    <td><input type="text" name="liason_lastname"></td>
    </tr>
    <tr>
    <td align="left">Organization</td>
    <td><input type="text" name="organization"></td>
    </tr>
    <tr>
    <td align="left">E-Mail Address</td>
    <td><input type="text" name="email"></td>
    </tr>
    <tr>
    <td align="left">Website / Blog</td>
    <td><input type="url" name="site_url"></td>
    </tr>
    <tr>
    <td align="left">Photo URL</td>
    <td><input type="url" name="img_url"></td>
    </tr>
    <tr>
    <td align="left">Address 1</td>
    <td><input type="text" name="address1"></td>
    </tr>
    <tr>
    <td align="left">Address 2</td>
    <td><input type="text" name="address2"></td>
    </tr>
    <tr>
    <td align="left">Address 3</td>
    <td><input type="text" name="address3"></td>
    </tr>
    <tr>
    <td align="left">Phone #</td>
    <td><input type="text" name="phone"></td>
    </tr>
    <tr>
    <td align="left">Notes</td>
    <td><TEXTAREA rows="5" cols="18" name="notes" wrap="physical"></TEXTAREA></td>
    </tr>
    <tr>
    <td colspan="4">


    <input type="submit" value="Add Liason" name="liason_submit"></td>
    </tr>
    <input type="hidden" name="_submit_check_liason" value="1"/>
    <input type="hidden" name="gl_liason_submit" value="process">
    </table>
    </form>

    <?php
    if (array_key_exists('_submit_check_liason', $_POST)) {
    echo("<?php $liasons_firstname $liason_lastname?> has been added!");
    }
    ?>

    </div>

  • Processing 2 Forms On One Page
    2007-10-28 19:33:00  jblifesetyles [Reply | View]

    Hi all... first, thanks in advance for the help.

    I have a php page with 2 forms one for creating a country, and another for creating a liason. The liason has to be assigned to a country that has been created in the first form.

    I get the form to load and everything, but it keeps posting blank rows back to the database. I'm a relative newb, hence the probably simple solution.

    Here's the full code for my form(s)

    [code]
    <?php

    /* Make sure we have admin rights */

    require_once('admin-header.php');
    require_once('admin.php');

    if (!current_user_can('edit_users') )
    wp_die(__('Cheatin’ uh?'));

    /* Posting to Countries */

    if (array_key_exists('gl_country_submit', $_POST)) {
    $addcountry = "INSERT INTO gl_countries VALUES('$country_id','$country_name','$flag_url','$thumb_url')";

    mysql_query($addcountry);

    print_r($addcountry);
    }

    /* Posting to Liasons */

    if (array_key_exists('gl_liason_submit', $_POST)) {
    $addliason = "INSERT INTO gl_liasons VALUES('$liason_id','$country_id2','$liason_firstname','$liason_lastname','$organization','$email','$site_url','$img_url','$address1','$address2','$address3','$phone','$notes')";

    mysql_query($addliason);

    print_r($addliason);
    }

    ?>

    <!-- Form to add a country -->

    <div class="wrap">
    <h2>Add Country</h2>
    <form method="post" action="<?php echo $PHP_SELF;?>">
    <input type="hidden" name="country_id" value="null">
    <table>
    <tr>
    <td align="left">Country</td>
    <td><input type="text" name="country_name"></td>
    </tr>
    <tr>
    <td align="left">Flag URL</td>
    <td><input type="url" name="flag_url"></td>
    </tr>
    <tr>
    <td align="left">Flag Thumbnail URL</td>
    <td><input type="url" name="thumb_url"></td>
    </tr>
    <tr>
    <td colspan="4">


    <input type="submit" value="Add Country" name="country_submit"></td>
    </tr>
    <input type="hidden" name="_submit_check_country" value="1"/>
    <input type="hidden" name="gl_country_submit" value="process">
    </table>
    </form>

    <?php
    if (array_key_exists('_submit_check_country', $_POST)) {
    echo("<?php $country_name?> is now svailable for Liasons!");
    }
    ?>
    </div>

    <!-- Form to add a liason -->

    <div class="wrap">
    <h2>Add Liason</h2>
    <form method="post" action="<?php echo $PHP_SELF;?>" >
    <input type="hidden" name="liason_id" value="null">
    <table>
    <tr>
    <td align="left">Country</td>
    <td><?php
    $query = "SELECT * FROM gl_countries";
    $results = mysql_query($query);
    echo '<select name="country_id">';
    while ($thisrow = mysql_fetch_array($results))
    {
    echo '<option value="'.$thisrow['country_id2'].'">'.$thisrow['country_name'].'</option>';
    }
    echo '</select>';?></td>
    </tr>
    <tr>
    <td align="left">First Name</td>
    <td><input type="text" name="liason_firstname"></td>
    </tr>
    <tr>
    <td align="left">Last Name</td>
    <td><input type="text" name="liason_lastname"></td>
    </tr>
    <tr>
    <td align="left">Organization</td>
    <td><input type="text" name="organization"></td>
    </tr>
    <tr>
    <td align="left">E-Mail Address</td>
    <td><input type="text" name="email"></td>
    </tr>
    <tr>
    <td align="left">Website / Blog</td>
    <td><input type="url" name="site_url"></td>
    </tr>
    <tr>
    <td align="left">Photo URL</td>
    <td><input type="url" name="img_url"></td>
    </tr>
    <tr>
    <td align="left">Address 1</td>
    <td><input type="text" name="address1"></td>
    </tr>
    <tr>
    <td align="left">Address 2</td>
    <td><input type="text" name="address2"></td>
    </tr>
    <tr>
    <td align="left">Address 3</td>
    <td><input type="text" name="address3"></td>
    </tr>
    <tr>
    <td align="left">Phone #</td>
    <td><input type="text" name="phone"></td>
    </tr>
    <tr>
    <td align="left">Notes</td>
    <td><TEXTAREA rows="5" cols="18" name="notes" wrap="physical"></TEXTAREA></td>
    </tr>
    <tr>
    <td colspan="4">


    <input type="submit" value="Add Liason" name="liason_submit"></td>
    </tr>
    <input type="hidden" name="_submit_check_liason" value="1"/>
    <input type="hidden" name="gl_liason_submit" value="process">
    </table>
    </form>

    <?php
    if (array_key_exists('_submit_check_liason', $_POST)) {
    echo("<?php $liasons_firstname $liason_lastname?> has been added!");
    }
    ?>

    </div>
    [/code]

  • Processing 2 Forms On One Page
    2007-10-28 19:32:31  jblifesetyles [Reply | View]

  • Unable to get form to work
    2007-10-17 11:31:58  jlbecker [Reply | View]

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html style="direction: ltr;"
    xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=ISO-8859-1" />
    <title>Employee Access Request Form</title>
    <style type="text/css">
    <!--
    .style1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: small;
    }
    .style2 {font-family: Arial, Helvetica, sans-serif}
    .style3 {}
    .style5 {font-family: Arial, Helvetica, sans-serif; color: #FFFFFF; }
    .style6 {color: #FFFFFF}
    .style7 {
    font-size: x-small;
    font-style: italic;
    }
    .style8 {font-size: x-small}
    .style9 {font-size: large}
    -->
    </style>
    </head>
    <body
    style="color: rgb(0, 0, 0); background-color: rgb(204, 204, 204);"
    alink="#000099" link="#000099" vlink="#990099">
    <form action="formsend.php" method="post">
    <table border="0" cellpadding="0" cellspacing="0"
    width="100%">
    <tbody>
    <tr>
    <td>
    <table border="0" cellpadding="1"
    cellspacing="1" width="100%">
    <tbody>
    <tr>
    <td>
    <div align="center">
    <h1 class="style2">Employee Access Request
    Form </h1>
    </div>
    </td>
    </tr>
    <tr>
    <td>
    <div class="style1" align="center">Fill
    out top 3 sections and hit submit button. Please allow adequate time
    for completion. </div>
    </td>
    </tr>
    </tbody>
    </table>
    </td>
    </tr>
    </tbody>
    </table>


    <table style="width: 100%; height: 68px;" bgcolor="#000000"
    border="0" cellpadding="1" cellspacing="1">
    <tbody>
    <tr>
    <td>
    <div class="style2" align="center">
    <h2 class="style6">Employee Information </h2>
    </div>
    </td>
    </tr>
    </tbody>
    </table>
    <table style="width: 100%;" border="0"
    cellpadding="1" cellspacing="1">
    <tbody>
    <tr>
    <td style="width: 33%;">
    <div class="style3" align="center">

    <input name="New_Employee"
    value="checkbox" type="checkbox" /> New Employee


    </div>
    </td>
    <td width="34%">
    <div align="center">

    <input
    name="Change_Employee" value="checkbox" type="checkbox" />Change
    Employee


    </div>
    </td>
    <td width="33%">
    <div align="center"> <input
    name="Delete_Employee" value="checkbox" type="checkbox" /><span
    class="style2">Delete Employee</span> </div>
    </td>
    </tr>
    </tbody>
    </table>
    <table border="0" cellpadding="1" cellspacing="1"
    width="100%">
    <tbody>
    <tr>
    <td width="40%"><span class="style2">First
    Name: <input name="First_Name" size="50" type="text" />
    </span></td>
    <td width="20%"><span class="style2">M.I.</span>:
    <input name="Middle_Initial" size="5"
    maxlength="1" type="text" /></td>
    <td width="40%"><span class="style2">Last
    Name:</span> <input name="Last_Name" size="50"
    type="text" /></td>
    </tr>
    </tbody>
    </table>
    <table border="0" cellpadding="1" cellspacing="1"
    width="100%">
    <tbody>
    <tr>
    <td width="50%"><span class="style2">Internal
    Phone: <input name="Internal_Phone" type="text" />
    </span></td>
    <td width="50%"><span class="style2">Start
    Date: <input name="Start_Date" type="text" /> </span></td>
    </tr>
    <tr>
    <td><span class="style2">Public Phone: <input
    name="Public_Phone" type="text" /> </span></td>
    <td><span class="style2">Title</span>:
    <input name="Title" type="text" /></td>
    </tr>
    <tr>
    <td><span class="style2">Department</span>:
    <input name="Department" type="text" /></td>
    <td><span class="style2">Location</span>:
    <input name="Location" type="text" /></td>
    </tr>
    <tr>
    <td><span class="style2">Voice Mail: <input
    name="Voice_Mail_Yes" value="checkbox" type="checkbox" />
    Yes     <input name="Voice_Mail_No"
    value="checkbox" type="checkbox" /> No</span></td>
    <td><span class="style2">Immediate
    Supervisor: <input name="Immediate_Supervisor" type="text" />
    </span></td>
    </tr>
    </tbody>
    </table>
    <table style="width: 100%; height: 82px;" border="0"
    cellpadding="1" cellspacing="1">
    <tbody>
    <tr>
    <td style="vertical-align: top;"><span
    class="style2">Additional
    Information: <textarea name="Additional_Information"
    cols="100"></textarea> </span></td>
    </tr>
    </tbody>
    </table>
    <table border="0" cellpadding="1" cellspacing="1"
    width="100%">
    <tbody>
    <tr>
    <td> </td>
    </tr>
    </tbody>
    </table>
    <table bgcolor="#000000" border="0" cellpadding="1"
    cellspacing="1" width="100%">
    <tbody>
    <tr>
    <td>
    <div class="style5" align="center">
    <h2 class="style2">Type of Access Needed </h2>
    </div>
    </td>
    </tr>
    </tbody>
    </table>
    <table style="width: 100%;" border="0"
    cellpadding="1" cellspacing="1">
    <tbody>
    <tr>
    <td style="width: 8%; vertical-align: top;"><input
    name="Email_Yes" value="checkbox" type="checkbox" />
    <span class="style2">Email </span></td>
    <td style="width: 44%; vertical-align: top;"><span
    class="style2">Distribution
    Lists: <input name="Distribution_Lists" size="50"
    type="text" /> </span></td>
    <td style="width: 18%; vertical-align: top;"><input
    name="FullCourt_Yes" value="checkbox" type="checkbox" />
    <span class="style2">FullCourt*</span></td>
    <td style="width: 21%; vertical-align: top;"><span
    class="style2"> <input name="PICS_n_KICS_Yes"
    value="checkbox" type="checkbox" /> PICS-n-KICS* <span
    class="style7">(the
    ability to view images through FullCourt)</span></span></td>
    <td style="width: 9%; vertical-align: top;"><input
    name="SAP_Yes" value="checkbox" type="checkbox" />
    <span class="style2">SAP</span> </td>
    </tr>
    </tbody>
    </table>
    <table style="width: 100%;" border="0"
    cellpadding="1" cellspacing="1">
    <tbody>
    <tr>
    <td style="width: 26%; vertical-align: top;"><span
    class="style2"> <input name="Work_Folders_Yes"
    value="checkbox" type="checkbox" /> Ability to work
    Imaging Folders </span></td>
    <td style="width: 34%; vertical-align: top;"><span
    class="style2">If so, for which libraries: <input
    name="CV_Yes" value="checkbox" type="checkbox" />
    CV   <input name="CR_Yes" value="checkbox"
    type="checkbox" /> CR   <input
    name="JV_Yes" value="checkbox" type="checkbox" />
    JV   <input name="CT_Yes" value="checkbox"
    type="checkbox" /> CT </span></td>
    <td style="width: 40%; vertical-align: top;"><span
    class="style2"> <input name="Attorney_Label_Program_Yes"
    value="checkbox" type="checkbox" /> Attorney Label
    Program    <input name="Label_Printer_Yes"
    value="checkbox" type="checkbox" /> Label Printer </span></td>
    </tr>
    </tbody>
    </table>
    <table style="width: 100%;" border="0"
    cellpadding="1" cellspacing="1">
    <tbody>
    <tr>
    <td style="vertical-align: top;"><span
    class="style2"> <input name="I_Leads_Yes"
    value="checkbox" type="checkbox" />I-Leads <span
    class="style8">(These two forms, Sheriff Security Access Awareness Statement (http://dcinfo/info/polform/awareness_statement.pdf)
    & Sedgwick County Non-Employee Information
    Technology Usage Agreement (http://dcinfo/info/polform/Sedgwick%20County%20Non-Employee%20Information%20Technology%20Usage%20Agreement.doc) , need to be signed and faxe to
    Eric Laney at 383-7600. This form, Sheriff
    Security Access Request (http://dcinfo/info/polform/background.doc) , needs to be filled out and sent back
    to us as an attachment.) </span></span></td>
    </tr>
    <tr>
    <td style="vertical-align: top;"><span
    class="style2"> <input name="Quash_Warrants_Yes"
    value="checkbox" type="checkbox" /> Ability to
    MANUALLY Quash warrants in
    I-Leads </span></td>
    </tr>
    <tr>
    <td style="vertical-align: top;"><span
    class="style2"> <input name="checkbox18"
    value="checkbox" type="checkbox" />E-Justice <span
    class="style8">(This form, Sheriff
    Security Access Request (http://dcinfo/info/polform/background.doc) , needs to be filled out and sent back
    to us as an attachment. This form, City Access Form (http://dcinfo/info/polform/Non-City%20SNP%20Access%20Form_Agree.doc) , needs to be
    filled out and e-mailed to Satin Siroky (ssiroky@wichita.gov) or faxed
    (858-7704) to start the process but signed originals must be mailed per
    the directions on the SNP form. The original documents will need to be
    submitted to the City's IT/IS Department M/S, Satin Siroky) </span></span></td>
    </tr>
    </tbody>
    </table>
    <table style="width: 100%;" border="0"
    cellpadding="1" cellspacing="1">
    <tbody>
    <tr>
    <td style="width: 19%; vertical-align: top;"><span
    class="style2"> <input name="CICS_Yes"
    value="checkbox" type="checkbox" /> CICS (mainframe) </span></td>
    <td style="width: 81%; vertical-align: top;"><span
    class="style2">Access
    equal to: <input name="Access_egual_to" type="text" />
    </span></td>
    </tr>
    </tbody>
    </table>
    <table style="width: 919px; height: 77px;" border="0"
    cellpadding="1" cellspacing="1">
    <tbody>
    <tr>
    <td
    style="width: 20%; vertical-align: top; font-family: Helvetica,Arial,sans-serif; text-align: left; height: 75px;">Additional
    Information:</td>
    <td style="width: 80%; vertical-align: middle; height: 75px;">
    <span class="style2"> <textarea
    rows="3" cols="100" name="Additional_Information"></textarea>
    </span></td>
    </tr>
    </tbody>
    </table>
    <table
    style="font-family: Helvetica,Arial,sans-serif; font-style: italic; width: 100%; height: 62px;"
    class="style2 style8" border="0" cellpadding="1"
    cellspacing="1">
    <tbody>
    <tr>
    <td style="vertical-align: top;"> * <span
    style="font-size: 8pt;">For FullCourt orientation, please
    contact dcithelp@dc18.org (mailto:dcithelp@dc18.org)
    for availability and
    dates.</span></td>
    </tr>
    </tbody>
    </table>
    <table bgcolor="#000000" border="0" cellpadding="1"
    cellspacing="1" width="100%">
    <tbody>
    <tr>
    <td>
    <h2 align="center"><span class="style5">Requesting
    Supervisor or Manager </span></h2>
    </td>
    </tr>
    </tbody>
    </table>
    <table border="0" cellpadding="1" cellspacing="1"
    width="100%">
    <tbody>
    <tr>
    <td width="34%"><span class="style2">Name</span>:
    <input name="Requesting_Name" type="text" /></td>
    <td width="33%"><span class="style2">Phone</span>:
    <input name="Requesting_Phone" type="text" /></td>
    <td width="33%"><span class="style2">Date</span>:
    <input name="Requesting_Date" type="text" /></td>
    </tr>
    </tbody>
    </table>
    <table border="0" cellpadding="1" cellspacing="1"
    width="100%">
    <tbody>
    <tr>
    <td> </td>
    </tr>
    </tbody>
    </table>
    <table bgcolor="#000000" border="0" cellpadding="1"
    cellspacing="1" width="100%">
    <tbody>
    <tr>
    <td>
    <div class="style2" align="center">
    <h2 class="style6">DCIT USE ONLY - DO NOT WRITE
    BELOW THIS LINE </h2>
    </div>
    </td>
    </tr>
    </tbody>
    </table>
    <table border="0" cellpadding="1" cellspacing="1"
    width="100%">
    <tbody>
    <tr>
    <td width="50%"><span class="style2">County
    UserID: <input name="County_UserID" type="text" />
    </span></td>
    <td width="51%"><span class="style2">Date
    SAR Submitted: <input name="SAR_Submitted" type="text" />
    </span></td>
    </tr>
    </tbody>
    </table>
    <table border="0" cellpadding="1" cellspacing="1"
    width="100%">
    <tbody>
    <tr>
    <td height="178">
    <table border="0" cellpadding="1"
    cellspacing="1" width="100%">
    <tbody>
    <tr>
    <td valign="top" width="8%">
    <div align="top"><span class="style2">Notes</span>:</div>
    </td>
    <td width="92%"><textarea name="Notes"
    cols="100" rows="10"></textarea></td>
    </tr>
    </tbody>
    </table>
    </td>
    </tr>
    </tbody>
    </table>
    <table border="0" cellpadding="1" cellspacing="1"
    width="100%">
    <tbody>
    <tr>
    <td>
    <div class="style9" align="center"> <input
    name="Submit" class="style9" value="Submit"
    type="submit" /> </div>
    </td>
    </tr>
    </tbody>
    </table>
    </form>
    </body>
    </html>

    I am using the following processing script

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?

    if ((!$First_Name) || (!$Middle_Initial) || (!$Last_Name) || (!$Internal_Phone) || (!$Public_Phone) || (!$Title) || (!$Department) || (!$Location) || (!$Immediate_Supervisor) || (!$Requesting_name) || (!$Requesting_Phone) || (!$Requesting_Date))
    {
    $display .= '<p align="center">All fields are required. Please check your information and try again.

    ';
    $display .= '

    Go back (javascript:history.back())

    ';

    }
    else{

    $New_Employee = $_POST['New_Employee'];
    $Change_Employee = $_POST['Change_Employee'];
    $Delete_Employee = $_POST['Delete_Employee'];
    $First_Name = $_POST['First_Name'];
    $Middle_Initial = $_POST['Middle_Initial'];
    $Last_Name = $_POST['Last_Name'];
    $Internal_Phone = $_POST['Internal_Phone'];
    $Public_Phone = $_POST['Public_Phone'];
    $Title = $_POST['Title'];
    $Department = $_POST['Department'];
    $Location = $_POST['Location'];
    $Voice_Mail_Yes = $_POST['Voice_Mail_Yes'];
    $Voice_Mail_No = $_POST['Voice_Mail_No'];
    $Immediate_Supervisor = $_POST['Immediate_Supervisor'];
    $Additional_Information = $_POST['Additional_Information'];
    $Email_Yes = $_POST['Email_Yes'];
    $Distribution_Lists = $_POST['Distribution_Lists'];
    $FullCourt_Yes = $_POST['FullCourt_Yes'];
    $PICS_n_KICS_Yes = $_POST['PICS_n_KICS_Yes'];
    $SAP_Yes = $_POST['SAP_Yes'];
    $Work_Folders_Yes = $_POST['Work_Folders_Yes'];
    $CV_Yes = $_POST['CV_Yes'];
    $CR_Yes = $_POST['CR_Yes'];
    $JV_Yes = $_POST['JV_Yes'];
    $CT_Yes = $_POST['CT_Yes'];
    $Attorney_Label_Program_Yes = $_POST['Attorney_Label_Program_Yes'];
    $Label_Printer_Yes = $_POST['Label_Printer_Yes'];
    $I_Leads_Yes = $_POST['I_Leads_Yes'];
    $Quash_Warrants_Yes = $_POST['Quash_Warrants_Yes'];
    $E_Justice_Yes = $_POST['E_Justice_Yes'];
    $CICS_Yes = $_POST['CICS_Yes'];
    $Access_equal_to = $_POST['Access_equal_to'];
    $Additional_information = $_POST['Additional_information'];
    $Requesting_name = $_POST['Requesting_name'];
    $Requesting_Phone = $_POST['Requesting_Phone'];
    $Requesting_Date = $_POST['Requesting_Date'];


    //Send form results to file
    //$fp = fopen("formresults.txt", "a");
    //fwrite($fp, $name . "," .
    // $email . "," .
    // $comments . "," .
    // date("M-d-Y") . "\n");
    //fclose($fp);

    // send form results through email
    $recipient = "jbecker@dc18.org";
    $subject = "Employee:"; "$First_Name"; "$Last_Name";
    $forminfo =
    (
    "Employee Information: \r".
    $New_Employee . "\r" .
    $Change_Employee . "\r" .
    $Delete_Employee . "\r" .
    $First_Name . "\r" .
    $Middle_Initial . "\r" .
    $Last_Name . "\r" .
    $Internal_Phone . "\r" .
    $Public_Phone . "\r" .
    $Title . "\r" .
    $Department . "\r" .
    $Location . "\r" .
    $Voice_Mail_Yes . "\r" .
    $Voice_Mail_No . "\r" .
    $Immediate_Supervisor . "\r" .
    $Additional_Information . "\r\r" .


    "Type of Access Needed: \r".
    Email_Yes . "\r" .
    $Distribution_Lists . "\r" .
    $FullCourt_Yes . "\r" .
    $PICS_n_KICS_Yes . "\r" .
    $SAP_Yes . "\r" .
    $Work_Folders_Yes . "\r" .
    $CV_Yes . "\r" .
    $CR_Yes . "\r" .
    $JV_Yes . "\r" .
    $CT_Yes . "\r" .
    $Attorney_Label_Program_Yes . "\r" .
    $Label_Printer_Yes . "\r" .
    $I_Leads_Yes . "\r" .
    $Quash_Warrants_Yes . "\r" .
    $E_Justice_Yes . "\r" .
    $CICS_Yes . "\r" .
    $Access_equal_to . "\r" .
    $Additional_information . "\r\r" .


    "Requesting Supervisor or Manager: \r".
    $Requesting_name . "\r" .
    $Requesting_Phone . "\r" .
    $Requesting_Date . "\r" .

    );

    $formsend = mail("$recipient", "$subject", "$forminfo", "From: $email\r\nReply-to:$email\r\n");
    $display .= '

    Thank you. You have successfully submitted the following information:

    ';
    $display .= nl2br($forminfo);
    }

    ?>
    <? echo $display; ?>
    </body>
    </html>
  • A name thats end with [] doesn't work well with JavaScript
    2007-08-16 08:43:43  Marion_Amsterdam [Reply | View]

    "2. Put [] at the end of the name of a multivalued form parameter."

    When using AJAX / JavaScript in your form, you'd better not use names/id's with [] at the end. It will make the form element inaccesibile for the JavaScript function document.getElementById() and you won't be able to address the element with document.mywebform.name[]. Solution: save the selected options as a string in a comma seperated list, and make this string the value of a hidden input element. In your php script, explode() this string
  • auto responder form handling in dynamic site
    2007-07-19 14:15:50  aegaron [Reply | View]

    We are currently using Plexum as our server. Recently we added an auto responder that can create an account for each "members" replicated site. The issue is getting the form used to join a mailing list to send the subscribers information to the correct members autoresponder. The form code for the AR using a hidden field which looks like:

    <form method="post" action="http://www.mysite.com/re/subc.php">
    <INPUT TYPE="HIDDEN" name="aid" value="1">

    The website uses PHP variables such as !ID! and !SITE_ID!. I need to figure out how to have the site know which value to assign to aid based on the !SITE_ID! the person is subscribing from.

    I am new to both autoresponders and PHP so any help or if more info is needed please let me know.

    Aaron
  • Mail function settings
    2007-07-13 23:53:42  kas22 [Reply | View]

    Hi there ,
    I'm so glad to be a member of this fourm..
    I would like to ask help of how to set the mail function at the (php.ini) so that I be able to write a mailing codes with php...

    thanks a lot.
  • Unable to process this Form Help please
    2006-09-12 20:18:52  vabril [Reply | View]

    <body>
    <form id="procedure" name="procedure" method="POST" action="results.php">

    <label></label>
    <label></label>


    <table width="800" border="0">
    <tr>
    <td align="center" valign="middle">

    SYNIVERSE METHOD OF PROCEDURE

    </td>
    </tr>
    </table>
    <fieldset id="general_info">
    <legend class="style6">General Information</legend>
    <table width="800" height="291" border="0" bgcolor="#F4F7FF" id="basic_Info">
    <tr>
    <td width="246">

    <span class="style2">Customer:</span>

    <span class="style3">Syniverse Technologies</span>

    </td>
    <td>

    <span class="style2">Location of Activity: </span>

    Tampa, FL

    </td>
    <td colspan="2"><label class="style3">
    Product
    <select name="select_pro" class="style2" id="select_pro">
    <option>ACCESSibility</option>
    <option>Analyzer</option>
    <option>Uniroam</option>
    <option>EDT</option>
    <option>CTP</option>
    </select>
    </label>
    <label class="style3"> </label>
    <label class="style3">Release #
    <input name="release_number" type="text" class="style2" id="release_number" value="2.46.00.3" size="12" maxlength="12" />
    </label></td>
    </tr>
    <tr>
    <th nowrap="nowrap"><span class="style3">Start Date:</span>

    <select name="start_month" size="1" class="style2" id="start_month">
    <option>Month</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>
    <label></label>
    <label>
    <select name="start_day" class="style2" id="start_day">
    <option>Day</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    </label>
    <select name="start_year" class="style2" id="start_year">
    <option>Year</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    </select>
    <label></label>
    </th>
    <th width="175" nowrap="nowrap">

    Start Time:

    <select name="start_time" class="style2" id="select">
    <option>00:00</option>
    <option>00:30</option>
    <option>01:00</option>
    <option>01:30</option>
    <option>02:00</option>
    <option>02:30</option>
    <option>03:00</option>
    <option>03:30</option>
    <option>04:00</option>
    <option>04:30</option>
    <option>05:00</option>
    <option>05:30</option>
    <option>06:00</option>
    <option>06:30</option>
    <option>07:00</option>
    <option>07:30</option>
    <option>08:00</option>
    <option>08:30</option>
    <option>09:00</option>
    <option>09:30</option>
    <option>10:00</option>
    <option>10:30</option>
    <option>11:00</option>
    <option>11:30</option>
    <option>12:00</option>
    <option>12:30</option>
    </select>

    <label>
    <select name="start_am" class="style2" id="start_am">
    <option>PM</option>
    <option>AM</option>
    </select>
    </label>

    </th>
    <th width="247" nowrap="nowrap"><span class="style3">End Date:</span>


    <select name="end_month" class="style2" id="end_month">
    <option>Month</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>
    <label></label>
    <label>
    <select name="end_day" class="style2" id="end_day">
    <option>Day</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    </label>
    <label>
    <select name="end_year" class="style2" id="end_year">
    <option>Year</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    </select>
    </label>
    </th>
    <th width="168" nowrap="nowrap">

    End Time:

    <select name="end_time" class="style2" id="select2">
    <option>00:00</option>
    <option>00:30</option>
    <option>01:00</option>
    <option>01:30</option>
    <option>02:00</option>
    <option>02:30</option>
    <option>03:00</option>
    <option>03:30</option>
    <option>04:00</option>
    <option>04:30</option>
    <option>05:00</option>
    <option>05:30</option>
    <option>06:00</option>
    <option>06:30</option>
    <option>07:00</option>
    <option>07:30</option>
    <option>08:00</option>
    <option>08:30</option>
    <option>09:00</option>
    <option>09:30</option>
    <option>10:00</option>
    <option>10:30</option>
    <option>11:00</option>
    <option>11:30</option>
    <option>12:00</option>
    <option>12:30</option>
    </select>

    <label>
    <select name="end_am" class="style2" id="end_am">
    <option>PM</option>
    <option>AM</option>
    </select>
    </label>

    </th>
    </tr>
    <tr>
    <td height="76">

    Back out Decision Time:
    <select name="backout_time" class="style2" id="select7">
    <option>00:00</option>
    <option>00:30</option>
    <option>01:00</option>
    <option>01:30</option>
    <option>02:00</option>
    <option>02:30</option>
    <option>03:00</option>
    <option>03:30</option>
    <option>04:00</option>
    <option>04:30</option>
    <option>05:00</option>
    <option>05:30</option>
    <option>06:00</option>
    <option>06:30</option>
    <option>07:00</option>
    <option>07:30</option>
    <option>08:00</option>
    <option>08:30</option>
    <option>09:00</option>
    <option>09:30</option>
    <option>10:00</option>
    <option>10:30</option>
    <option>11:00</option>
    <option>11:30</option>
    <option>12:00</option>
    <option>12:30</option>
    </select>

    <select name="backout_pm" class="style2" id="select8">
    <option>PM</option>
    <option>AM</option>
    </select>

    </td>
    <td colspan="2"><div align="left"><span class="style3">RMS Number (if applicable):</span>
    <input name="rms_number" type="text" class="style2" id="rms_number" size="8" maxlength="4" />
    </div>
    <label>
    <div align="center"></div>
    </label>
    Back out Duration:
    <label>
    <input name="back_out_dura" type="text" class="style2" id="back_out_dura" size="8" maxlength="6" />
    </label> </td>
    <td>

    TSG Number:
    <label>
    <input name="tsg_number" type="text" class="style2" id="tsg_number" size="24" maxlength="24" />


    Escalation Notification: </label>
    <label>
    <input name="escal_notify" type="text" class="style2" id="escal_notify" size="24" maxlength="20" />
    </label>

    </td>
    </tr>
    <tr>
    <td height="71" colspan="4">

    General Description of Work:


    <label>
    <textarea name="gen_desc" cols="75" rows="4" class="style2" id="gen_desc"></textarea>
    </label>

    </td>
    </tr>
    <tr>
    <td colspan="4"><span class="style3">Install on:</span>
    <label class="style2">rpteng01
    <input type="checkbox" name="checkbox" value="checkbox" />
    </label>
    <label class="style2">rpteng02
    <input type="checkbox" name="checkbox2" value="checkbox" />
    </label>
    <label class="style2">rpteng03
    <input type="checkbox" name="checkbox3" value="checkbox" />
    </label>
    <label class="style2">rpteng04
    <input type="checkbox" name="checkbox4" value="checkbox" />
    </label>
    <label class="style2">dweudb-lh
    <input type="checkbox" name="checkbox5" value="checkbox" />
    </label>
    <label class="style2">accwebdl-lh
    <input type="checkbox" name="checkbox6" value="checkbox" />
    </label>
    <label class="style2">acdwapp-lh
    <input type="checkbox" name="checkbox7" value="checkbox" />
    </label>
    <label class="style2">accapp-lh
    <input type="checkbox" name="checkbox8" value="checkbox" />
    </label>
    <label class="style2">schlitz
    <input type="checkbox" name="checkbox9" value="checkbox" />
    </label>
    <label class="style2"></label></td>
    </tr>
    </table>
    <table width="800" border="0" bgcolor="#F4F7FF">
    <tr>
    <td width="549"><span class="style3">Additional Notes:


    <textarea name="textfield5" cols="75" rows="3" class="style2"></textarea>
    </span>

    </td>
    <td width="225"><label class="style3"></label>
    <span class="style3">TIMELINE</span>

    <span class="style2">
    <label class="style2">
    <input name="pre_install" type="text" class="style2" id="pre_install" value="00:00:PM" size="15" maxlength="8" />
    Pre-Activity</label>
    </span>

    <span class="style2">
    <label>
    <input name="textfield" type="text" class="style2" value="00:00:PM" size="15" maxlength="8" />
    Backup</label>
    <label class="style2"></label>


    <label class="style2">
    <input name="textfield2" type="text" class="style2" value="00:00:PM" size="15" maxlength="8" />
    Perform Install</label>
    </span>

    <label class="style2">
    <input name="textfield3" type="text" class="style2" value="00:00:PM" size="15" maxlength="8" />
    Validation</label></td>
    </tr>
    </table>
    </fieldset>
    <fieldset id="pre_activity">
    <legend class="style6">Pre-activity Procedures</legend>
    <table width="800" border="0">
    </table>
    <table width="800" border="0" bgcolor="#F4F7FF">
    <tr>
    <td width="61" class="style3">Step # </td>
    <td width="118" class="style3"><div align="center">Estimate Time

    For Completion </div></td>
    <td width="607"><div align="center">This procedure outlines steps for tasks to be performed prior to the scheduled activity.</div></td>
    </tr>
    <tr>
    <td><label>
    <select name="step_1" size="1" class="style2" id="step_1">
    <option>#1</option>
    <option>#2</option>
    <option>#3</option>
    <option>#4</option>
    </select>
    </label></td>
    <td><label>
    <select name="estimate_1" class="style2" id="estimate_1">
    <option>5-min</option>
    <option>10-min</option>
    <option>15-min</option>
    <option>20-min</option>
    <option>25-min</option>
    <option>30-min</option>
    <option>35-min</option>
    <option>40-min</option>
    <option>45-min</option>
    <option>50-min</option>
    <option>55-min</option>
    <option>1-Hour</option>
    <option>2-Hour</option>
    <option>3-Hour</option>
    <option>4-Hour</option>
    <option>5-Hour</option>
    </select>
    </label></td>
    <td><label>
    <textarea name="pre_step1" cols="85" rows="3" class="style2" id="pre_step1"></textarea>
    </label></td>
    </tr>
    <tr>
    <td><select name="step_2" size="1" class="style2" id="select3">
    <option>#1</option>
    <option>#2</option>
    <option>#3</option>
    <option>#4</option>
    </select></td>
    <td><select name="estimate_2" class="style2" id="select5">
    <option>5-min</option>
    <option>10-min</option>
    <option>15-min</option>
    <option>20-min</option>
    <option>25-min</option>
    <option>30-min</option>
    <option>35-min</option>
    <option>40-min</option>
    <option>45-min</option>
    <option>50-min</option>
    <option>55-min</option>
    <option>1-Hour</option>
    <option>2-Hour</option>
    <option>3-Hour</option>
    <option>4-Hour</option>
    <option>5-Hour</option>
    </select></td>
    <td><textarea name="pre_step2" cols="85" rows="3" class="style2" id="pre_step2"></textarea></td>
    </tr>
    <tr>
    <td><select name="step_3" size="1" class="style2" id="select4">
    <option>#1</option>
    <option>#2</option>
    <option>#3</option>
    <option>#4</option>
    </select></td>
    <td><select name="estimate_3" class="style2" id="select6">
    <option>5-min</option>
    <option>10-min</option>
    <option>15-min</option>
    <option>20-min</option>
    <option>25-min</option>
    <option>30-min</option>
    <option>35-min</option>
    <option>40-min</option>
    <option>45-min</option>
    <option>50-min</option>
    <option>55-min</option>
    <option>1-Hour</option>
    <option>2-Hour</option>
    <option>3-Hour</option>
    <option>4-Hour</option>
    <option>5-Hour</option>
    </select></td>
    <td><textarea name="pre_step3" cols="85" rows="3" class="style2" id="pre_step3"></textarea></td>
    </tr>
    </table>
    </fieldset>
    <fieldset id="activity_install">
    <legend class="style6">Activity / Install</legend>
    <table width="800" border="0">
    </table>
    <table width="800" border="0" bgcolor="#F4F7FF">
    <tr>
    <td width="71" class="style3">Step#</td>
    <td width="99"><div align="center">Estimated Time For Completion</div></td>
    <td width="616">This procedure outlines steps for tasks to be performed for the scheduled activity.</td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    <td><textarea name="activity_1" cols="85" rows="3" class="style2" id="activity_1"></textarea></td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    <td><textarea name="activity_2" cols="85" rows="3" class="style2" id="activity_2"></textarea></td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    <td><textarea name="activity_3" cols="85" rows="3" class="style2" id="activity_3"></textarea></td>
    </tr>
    </table>
    </fieldset>

    <label></label>
    <label></label>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>


    </form>
    <label></label>
    </body>
  • mod to 'print a radio button or checkbox'
    2006-08-11 08:08:32  harley1387 [Reply | View]

    Can alternatively use this function that will allow for multiselect checkboxes too. Will need to modify the form handling to process these elements as an array.

    //print a radio button or checkbox
    function input_radiocheck($type, $element_name, $values, $element_value) {
    print '<input type="' . $type . '" name="' . $element_name .'[]" value="' . $element_value . '" ';
    if (in_array($element_value , $values[$element_name])) {
    print ' checked="checked"';
    }
    print '/>';
    }

    Usage:
    input_radiocheck('checkbox','contact', $_POST, 'email');
    input_radiocheck('checkbox','contact', $_POST, 'mail');
    input_radiocheck('checkbox','contact', $_POST, 'phone');

  • Form submission question
    2006-03-06 05:54:16  miles&miles [Reply | View]

    Hi,

    I am just a little bit confused about the submit check that the author talks about at the beginning of the article.

    He says using the following code on the form:

    <input type="hidden" name="_submit_check" value="1"/>

    and then checking its presence with the following code:


    if (array_key_exists('_submit_check', $_POST)) {
    /* ... do something with the form parameters ... */
    }


    will avoid problems when users press enter instead of the submit button.

    What I don't understand is what stops the hidden field being sent when enter is pressed. Basically I dont understand how using this code differentiates between a enter key or a submit button being pressed.

    Can anyone clear this up for me?

    Thanks

  • hi!!! from Lima Perú
    2006-01-27 14:31:04  julito_montoya [Reply | View]

    hi there I just modified your source code hope to help somebody!!
    byeee
    Julio
    gugli100@gmail.com



    <?php


    function validate_form(){
    echo "<br>validado";
    if (isset( $_POST['input1'] )) $input1 = $_POST['input1'];
    if (isset( $_POST['input2'] )) $input2 = $_POST['input2'];
    if (isset( $_POST['input3'] )) $input3 = $_POST['input3'];

    if ($input1==1)
    $ListaErrores["Error1"]="Ingrese la 1";
    if ($input2==2)
    $ListaErrores["Error2"]="Ingrese la 2";
    if ($input3==3)
    $ListaErrores["Error3"]="Ingrese la 3";

    return $ListaErrores;
    }


    function show_form(){

    if ($num_args = func_num_args()>0)
    $Errores=func_get_arg(0);

    echo '<form method="POST" action="';
    echo $_SERVER['PHP_SELF'];
    echo '">';
    echo 'NUMBER1 <input name="input1" type="text" />'; echo $Errores["Error1"]; echo "
    ";
    echo 'NUMBER2 <input name="input2" type="text" />'; echo $Errores["Error2"]; echo "
    ";
    echo 'NUMBER3 <input name="input3" type="text" />'; echo $Errores["Error3"]; echo "
    ";
    echo '<input type="hidden" name="_submit_check" value="1"/>
    <input type="submit" name="Order">
    </form>
    ';
    }

    function process_form(){
    echo "
    procesado";
    //ejecuto el controliu

    }


    //--------------------------------------------------------------------------

    if (array_key_exists('_submit_check',$_POST)) {
    // If validate_form() returns errors, pass them to show_form()
    if ($form_errors = validate_form()) {
    show_form($form_errors);
    } else {
    // The submitted data is valid, so process it
    process_form();
    }
    } else {
    // The form wasn't submitted, so display
    show_form();
    }


    ?>

  • Real World Example of Same
    2006-01-19 19:23:30  zinc_chameleon [Reply | View]

    Wouldn't you know it, my employer wanted select forms day one. There's two very important things to add to this example:
    First:

    <SELECT name="myselection[]" multiple>

    has to be written EXACTLY as shown; HTML can handle a lot of variations on the syntax, but PHP5 can't. Second: Whatever script you pass this variable two, it has to be intialized to 0.

    $ms = $_POST[myselection][0];
  • It doesn't make sense to use print
    2006-01-03 20:41:40  Gustavoang [Reply | View]

    It doesn't make sense to use print instead of echo in these snippets of scripts.

    Take a look at: http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40

    --
    Gustavo Narea.
  • Chris Shiflett photo Be careful with $_SERVER
    2005-11-13 01:52:32  Chris Shiflett | O'Reilly Author [Reply | View]

    $_SERVER['PHP_SELF'] is tainted.
  • form handling
    2005-09-20 13:43:10  lonki [Reply | View]

    Maybe it is a good idea if the authors of articles will visit some sites like hardenedphp:

    http://forum.hardened-php.net/viewtopic.php?id=20

    Regards,
  • Testing
    2005-06-22 12:42:49  nabilaffan [Reply | View]

    Is it working ?
  • Form submission with hidden element
    2004-11-15 21:58:56  az_pete [Reply | View]

    You mentioned: testing for the presence of a hidden element avoids problems that can result from browsers' varying behaviors when a user submits a form by pressing the Enter key instead of clicking a submit button.
    Could you elaborate on the problems that result when a user presses the enter key versus clicking the submit button?
    I have generally just tested for the value of the submit button within my scripts instead of having to manage another form element (e.g. if (isset($_POST['submit_button_value'])) {process form} ). Is this not as good a method? Any thoughts would be appreciated.
    Thanks.
  • ad htmlentities
    2004-09-30 15:47:58  llook.wz.cz [Reply | View]

    Do not use htmlentities() for encoding any data! Please, use the htmlspecialchars(). Htmlentities encodes everything what is possible to encode, but htmlspecialchars encodes only the characters which are necessary to encode.
    Htmlentities is acceptable only if you exactly know the input and output encoding.
    That's problem of some languages using special chars (e.g. Czech).
  • Radio button values to another page.
    2004-09-15 11:28:47  johnsherman [Reply | View]

    How can I pass the value from a selected radio button to a second page? I am able to pass all other values from the form, but not the button value.


Tagged Articles

Post to del.icio.us

This article has been tagged:

php

Articles that share the tag php:

Understanding MVC in PHP (477 tags)

The PHP Scalability Myth (123 tags)

The Dynamic Duo of PEAR::DB and Smarty (53 tags)

PHP Form Handling (43 tags)

Very Dynamic Web Interfaces (39 tags)

View All

programming

Articles that share the tag programming:

Rolling with Ruby on Rails (1374 tags)

Very Dynamic Web Interfaces (279 tags)

Ajax on Rails (231 tags)

Understanding MVC in PHP (202 tags)

A Simpler Ajax Path (186 tags)

View All

forms

Articles that share the tag forms:

ASP.NET Forms Authentication - Part 1 (7 tags)

PHP Form Handling (6 tags)

XML Forms, Web Services and Apache Cocoon (3 tags)

Form Validation (2 tags)

View All

webdev

Articles that share the tag webdev:

Rolling with Ruby on Rails (351 tags)

Very Dynamic Web Interfaces (163 tags)

Understanding MVC in PHP (96 tags)

A Simpler Ajax Path (93 tags)

Ajax on Rails (61 tags)

View All

form

Articles that share the tag form:

PHP Form Handling (4 tags)

Getting Started with PHP's HTML_QuickForm (2 tags)

View All

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com