Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'php handle forms'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. Placing this in 4th Edition as that's the book I'm working through. I've created a form with three inputs (Agent, Guest, Email) but Agent is not required. I'm trying to display different messages whether Agent is input or not but cannot get that part to work. I know the reset button doesn't work but that's just as the form was copied from an old html page. I'll get into field content validation once I can get past this stage as I have multiple fields to add but need to display different messages on form submission dependent on which fields get completed. <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html" charset="utf-8"> <title>frm_request_home</title> </head> <body> <?php // Start input validation: // Validate the Agent: if (!empty($_POST['agent'])) { $agent = $_POST['agent']; } else { $agent = NULL; } // Validate the Guest Name: if (!empty($_POST['guest'])) { $guest = $_POST['guest']; } else { $guest = NULL; echo '<p class="error"> You forgot to enter the guest name!</p>'; } // Validate the Email Address: if (!empty($_POST['email'])) { $email = $_POST['email']; } else { $guest = NULL; echo '<p class="error"> You forgot to enter your email address!</p>'; } // Conditional to check for form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // form validation: if (!isset($_POST['agent']) ) { // Print the results if Agent: echo "<p>Thank you <b>$agent</b> for your request for <b>$guest</b>.</p> <p>We will reply to you at <i>$email</i>.</p>\n"; // Print the results if Guest: } elseif (!empty($_POST['guest']) && !empty($_POST['email']) ) { echo "<p>Thank you, <b>$guest</b>, for your request.</p> <p>We will reply to you at <i>$email</i>.</p>\n"; } else { // missing form value. echo '<p class"error"> Please fill out the form again.</p>'; } } // Leave the PHP section and create the HTML form: ?> <table width="98%" border="0" align="center" cellpadding="2" cellspacing="0" class="tblBorder"> <tr> <td align="center" class="txtHeaderRev">Request Form</td> </tr> <tr> <td> <form action="frm_request_home.php" method="post"> <table width="86%" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td align="right" class="txtMain">Agency Name (if applicable):</td> <td><input type="text" name="agent" value="<?php if (isset($_POST['agent'])) echo $_POST['agent']; ?>" style="width:250px;" /></td> </tr> <tr> <td width="46%" align="right" class="txtMain">Guest Name :</td> <td><input type="text" name="guest" value="<?php if (isset($_POST['guest'])) echo $_POST['guest']; ?>" style="width:250px;" /></td> </tr> <tr> <td align="right" class="txtMain">Email Address:</td> <td><input type="text" name="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" style="width:250px;" /></td> </tr> <tr> <td>&nbsp;</td> <td> <input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /> </td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> </form> </td> </tr> </table> </body> </html>
×
×
  • Create New...