Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To 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 29th, 2007, 05:57 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default IF Statement

I have created a form where a customer can fill their details, and the following is the code i have used to process this form. Currently i have got code that makes sure that all fields are filled in, but i was hoping to change this.

If a customer fills in the date field for time lived at original address and if this is over 3 years then the fields for previous address and 2nd previous do not need to be filled in. Is this possible?

Code:
if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] != "POST") {
    exit("<p>You did not press the submit button; this page should not be accessed directly.</p>");
} else {
    $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i";
    $profanity = "/*** REMOVED BY ADMINISTRATOR ***/i";
    $spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazolam|ambien|ambian|amoxicillin|antivert|blackjack|backgammon|texas|holdem|poker|carisoprodol|ciara|ciprofloxacin|debt|dating|porn)/i";
    $bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i";

    if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) {
        exit("<p>Known spam bots are not allowed.</p>");
    }
    foreach ($_POST as $key => $value) {
        $value = trim($value);

        if (empty($value)) {
            exit("<p>Empty fields are not allowed. Please go back and fill in the form properly.</p>");
        } elseif (preg_match($exploits, $value)) {
            exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>");
        } elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) {
            exit("<p>That kind of language is not allowed through our form.</p>");
        }

        $_POST[$key] = stripslashes(strip_tags($value));
    }

    if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) {
        exit("<p>That e-mail address is not valid, please use another.</p>");
    }

    $recipient = "myemail@domain.com";

    $subject = "You have a new order";

        $message = "Order Form: \n";
        $message .= "Title: {$_POST['title']} \n";
        $message .= "Forename: {$_POST['forename']} \n";
    $message .= "Surname: {$_POST['surname']} \n";
    $message .= "Home Address: {$_POST['haddress']} \n";
    $message .= "Town: {$_POST['htown']} \n";
    $message .= "Postcode: {$_POST['hpostcode']} \n";
    $message .= "Time At Current Address: {$_POST['htime']} Years {$_POST['htime2']} \n";
    $message .= "Billing Address: {$_POST['baddress']} \n";
    $message .= "Town: {$_POST['btown']} \n";
    $message .= "Billing Postcode: {$_POST['bpostcode']} \n";
    $message .= "Occupation: {$_POST['jobtitle']} \n";
    $message .= "Time With Present Employer: {$_POST['jobtime']} Years {$_POST['jobtime2']} \n";
    $message .= "Marital Status: {$_POST['marital']} \n";
    $message .= "Date of Birth: {$_POST['dob']}/{$_POST['dobm']}/{$_POST['doby']} \n";
    $message .= "Telephone: {$_POST['telephone']} \n";
    $message .= "Mobile: {$_POST['mobile']} \n"; 
    $message .= "Previous Address: {$_POST['paddress']} \n";
    $message .= "Town: {$_POST['ptown']} \n";
    $message .= "Postcode: {$_POST['ppostcode']} \n";
    $message .= "Time At Address: {$_POST['ptime']} Years {$_POST['ptimem']} \n";
    $message .= "Second Previous Address: {$_POST['paddress2']} \n";
    $message .= "Town: {$_POST['ptown2']} \n";
    $message .= "Postcode: {$_POST['ppostcode2']} \n";
    $message .= "Time At Address: {$_POST['ptime2']} Years {$_POST['ptimem2']} \n";
    $message .= "Accomodation Type: {$_POST['accom']} \n";
    $message .= "Occupation Type: {$_POST['occ']} \n"; 
    $message .= "Proof of Address: {$_POST['proof']} \n";  
    $message .= "Date of Birth: {$_POST['dproof']}/{$_POST['dproofm']}/{$_POST['dproofy']} \n";   
    $message .= "E-mail: {$_POST['email']} \n";
    $message .= "Country: {$_POST['country']} \n";
    $headers = "From: Sacranie-Mobiles.co.uk <$recipient> \n";
    $headers .= "Reply-To: <{$_POST['email']}>";

    if (mail($recipient,$subject,$message,$headers)) {
        echo "<p>Thank you! Your order has now been placed. We will be in touch shortly.</p>";
    } else {
        echo "<p>Sorry, there was an error and your mail was not sent. Please find an alternative method of contacting the webmaster.</p>";
    }
}
?>
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
if/else statement mussa Beginning PHP 5 July 3rd, 2006 06:06 PM
What does the @ do in the following statement? kenn_rosie VB.NET 2002/2003 Basics 1 March 15th, 2006 12:20 PM
Like Statement Nitin_sharma Oracle ASP 2 May 10th, 2005 12:18 AM
Like Statement Nitin_sharma Oracle 4 February 12th, 2005 01:46 PM
Like statement Nitin_sharma Classic ASP Databases 7 February 1st, 2005 11:12 AM



All times are GMT -4. The time now is 05:35 PM.


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