Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 4th, 2008, 10:44 AM
twr twr is offline
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default php5 chap 15 help needed

In the try/catch script, it will validate no problem but thats all. just returns the filled out form and not the text results.

the problem seems to be
 if (!is_object($e) and isset($posted)) {

    echo "Thanks for your entry. We'll be in touch.";

can anyone help with this please.
Regards

Reply With Quote
  #2 (permalink)  
Old January 5th, 2008, 06:20 AM
twr twr is offline
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still not sorted this out, so i thought i should paste in the full script.

<html>
<head><title>Beginning PHP5</title></head>
<body bgcolor="#FFFFFF">
<?php
if (isset($_POST['posted'])) {

   //put the submitted values into regular variables

   $first_name = $_POST['first_name'];
   $last_name = $_POST['last_name'];
   $birth_date = $_POST['birth_date'];
   $phone = $_POST['phone'];
   $age = $_POST['age'];
   $address = $_POST['address'];
   $city = $_POST['city'];
   $state = $_POST['state'];
   $postal_code = $_POST['postal_code'];

    //make an array of field names and data types

    $field_names = array("first_name" => "string",
                "last_name" => "string",
                "birth_date" => "date",
                "phone" => "string",
                "age" => "integer",
                "address" => "string",
                "city" => "string",
                "state" => "string",
                "postal_code" => "string");

    //try checking the data type of each submitted value based on the name of the field

    function form_validate($fns) {

        foreach ($fns as $key => $value) {

            $field_value = $key;

            global $$field_value;

            //echo "actual field value is " . $$field_value . "<br>";

            switch ($value) {

                Case "string";

                    if ((strlen($$field_value) < 1) or (strlen($$field_value) > 99)) {
                        throw new Exception("Please enter a string value between 1 and 100 characters in the <b>$key</b> field");
                    }

                    break;

                Case "date";

                    if (!ereg("^[0-9]{4}\-([1-9]|(0[1-9])|(1[0-2]))\-([1-9]|(0[1-9])|([1-2][0-9])|3[0-1])$",$$field_value)) {

                        throw new Exception("Please enter a valid date formatted as YYYY-MM-DD in the <b>$key</b> field");
                    }

                    break;

                Case "integer";

                    if (!is_numeric($$field_value)) {

                        throw new Exception("Please enter a number without decimal places or alphabetical characters in the <b>$key</b> field.");
                    }

                    break;

                default;

                    break;

            }
        }
    }

    //catch the exception and produce an error message

    try
    {
        form_validate($field_names);
    }

    catch (Exception $e)
    {
        echo $e->getMessage();
        echo "<br>";

    }

}

//if no errors thank the user
 if (!is_object($e) and isset($posted)) {

    echo "Thanks for your entry. We'll be in touch.";
} else {

//return the filled out form to the user and ask them to try again

?>

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
chap 15 manal_sag BOOK: Beginning ASP 3.0 2 July 10th, 2005 03:29 AM
help in chap 15 manal_sag BOOK: Beginning ASP 3.0 2 May 25th, 2005 02:59 AM
Pro PHP5, Ch.15, Class file usage BillD Pro PHP 0 April 7th, 2005 11:08 PM
Professional PHP5 Ch. 15 Custom Session Handler superrobotpope Pro PHP 4 February 4th, 2005 08:32 PM
Sessions - Chap 15 mminnie BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 1 January 10th, 2005 04:25 AM



All times are GMT -4. The time now is 04:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.