Form question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
turbodurso
Forum Newbie
Posts: 1
Joined: Thu Sep 04, 2008 4:55 am

Form question

Post by turbodurso »

Hello there!

I have the following code to process my form, and it just doesnt work and i'm a bit stuck now because i have no clue as to what the error is ...

Could someone please have a quick look?

Thanks!

(form at : http://www.turbodurso.dreamhosters.com/ ... /form.html)

Code: Select all

<?php
/*****************************************
* @scriptname:        /SCRITP NAME HERE/    
* @author:        /NAME/
* @version:        /VERSION/
* @date:            /ADD DATE HERE/
******************************************
* @functionality:
*        /ADD DESCRIPTION HERE/
*        
******************************************
* @updated by:        
* @updated date:        
* @changes:
*
******************************************
* @notes:
*
******************************************/
 
function redirect($url) {
    if (!headers_sent()) {
        //If headers not sent yet... then do php redirect
        header('Location: '.$url); exit;
    } else {
        //If headers are sent... do javascript redirect... if javascript disabled, do html redirect.
        echo '<script type="text/javascript">';
        echo 'window.location.href="'.$url.'";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
        echo '</noscript>'; exit;
    }
}
 
// Variables
$name    = $_POST['name'];
$lastname = $_POST['name'];
$address    = $_POST['address'];
$city    = $_POST['city'];
$postcode    = $_POST['postcode'];
$country    = $_POST['country'];
$action    = $_REQUEST['action'];
 
//Patterns
$exploits        = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i";
$profanity    = "/(beastial|bestial|blowjob|clit|****|***|cunilingus|cunillingus|cunnilingus|****|ejaculate|fag|felatio|fellatio|****|fuk|fuks|gangbang|gangbanged|gangbangs|hotsex|jism|jiz|kock|kondum|kum|kunilingus|orgasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|porn|pussies|pussy|spunk|xxx)/i";
$spamwords    = "/(<span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>|<span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>|<span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>|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";
 
// Error Counter
$error = 0; 
 
// Check the user action
if($action == 'submitform') {
    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)) {
            echo("<p>Please make sure you have filled out the required fields.</p>");
            $error++;
        } elseif (preg_match($exploits, $value)) {
            echo("<p>Exploits/malicious scripting attributes aren't allowed.</p>");
            $error++;
        } elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) {
            echo("<p>That kind of language is not allowed through our form.</p>");
            $error++;
        } 
 
        if($error == 0) {
            $_POST[$key] = stripslashes(strip_tags($value));
        } else {
            exit("There was a problem with your input");
        }
    }
 
    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 = "india.id@gmail.com";
    $subject = "Application Form Mail";
 
    $message = "Hello, you've received an e-mail through your website application form: \n";
    $message .= "First name: {$_POST['name']} \n";
    $message .= "Last name: {$_POST['lastname']} \n";
    $message .= "Address: {$_POST['address']} \n";
    $message .= "City: {$_POST['city']} \n";
    $message .= "County: {$_POST['county']} \n";
    $message .= "Postcode: {$_POST['postcode']} \n";
    $message .= "Country: {$_POST['country']} \n";
    $message .= "Email: {$_POST['email']} \n";
    $message .= "Tel: {$_POST['tel-contact']} \n";
    $message .= "Mob: {$_POST['mob-contact']} \n";
    $message .= "Comments: {$_POST['comments']} \n";
 
    $headers = "From: UNTITLED MUSE <$recipient> \n";
    $headers .= "Reply-To: <{$_POST['email']}>";
 
    $sucess = mail($recipient,$subject,$message,$headers);
 
    if ($sucess) {
        //Success URL
        $url = "http://www.turbodurso.dreamhosters.com/untitledmuse/form/success.html";
        redirect($url);
    } else {
        echo "<p>Sorry, there was an error and your mail was not sent. Please find an alternative method of contacting the webmaster.</p>";
    }
} else {
    exit("<p>You did not press the submit button; this page should not be accessed directly.</p>");    
}
 
?>
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Form question

Post by andyhoneycutt »

the page you've linked is redirecting my browser too quickly for me to be able to look at the errors. from what i was able to catch, it looks like a problem with the regular expression you are running against the email address that is entered. could you post the error message you are receiving?
Post Reply