Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Struggling with form

    Hi,

    ive been using dreamweaver fo about a year now, i have managed to get create a form with a spam filter however on trying to add radio buttons and list menus to the form which are required to send an automatic reponse(send back a price list based on there selected options) i have hit a brick wall!

    please can someone tell me if the method used below is anywhere near possible to achieve this.

    PHP Code:
    <?php 
    $to 
    "info@myemail.co.uk";
    $from $_REQUEST['contact_email'];
    $fname $_REQUEST['contact_firstname'];
    $lname $_REQUEST['contact_surname'];
    $check1 = ['adult_button'];
    $check2 = ['junior_button'];
    $size = ['groupsize'];
    $headers "From: $from"
    $subject "Database Entry";
    $subject2 "Kart Racing";
    $auto1 "adults 0 - 8";
    $auto2 "adults 8 - 16";
    $auto3 "adults 16 - 20";
    $auto4 "adults 20 - 44";
    $auto5 "adults 44+";
    $auto6 "juniors 0 - 8";
    $auto7 "juniors 8 - 16";
    $auto8 "juniors 16 - 20";
    $auto9 "juniors 20 - 44";
    $auto10 "juniors 44+";

    $fields = array(); 
    $fields{"contact_firstname"} = "First Name:"
    $fields{"contact_surname"} = "Last Name:";
    $fields{"contact_telephone"} = "Phone:";
    $fields{"contact_email"} = "Email:"
    $fields{"contact_groupsize"} = "Group Size:";
    $fields{"contact_date"} = "Event Date:"
    $fields{"contact_comments"} = "Additional Comments"

    $bad_patterns = Array (  
    'b*cc\s*:',  
    'to\s*:',  
    'content\-type',  
    '\[\s*URL.*\]*',
    '\[\s*LINK.*\]*',  
    '\%5B\s*URL.*(\%5D)*',  
    '\%5B\s*LINK.*(\%5D)*',  
    '\[\s*a\s*href.*\]*',  
    '\%5B\s*a\s*href.*(\%5B)*',  
    '\<\s*a\s*href.*\>*',  
    '\%3C\s*a\s*href.*(\%3E)*',  
    'viagra';

    foreach (
    $_REQUEST as $key=>$value) { filter_spam($bad_patterns,$value);}

    $body "We have recieved a specail offer booking:\n\n"; foreach($fields as $a => $b)
    {
    $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);}

    if(
    $fname == '') {print "You have not entered your first name, please go back and try again";}
    else {
    if(
    $lname == '') {print "You have not entered your surname, please go back and try again";}
    else {
    if(
    $from == '') {print "You have not entered an email address, please go back and try again";}
    else {

    if(
    $check1 == 'checked') {{if ($size == '1') {print "please specify a group size";}
    else {if(
    $size == '2') {$send2 mail($from$subject2$auto1);}
    else {if(
    size == '3') {$send3 mail($from$subject2$auto2);}
    else {if(
    size == '4') {$send4 mail($from$subject2$auto3);}
    else {if(
    size == '5') {$send5 mail($from$subject2$auto4);}
    else {if(
    size == '6') {$send6 mail($from$subject2$auto5);}
    }
    }
    }
    }
    }
    }
    }
    else {if(
    $check2 == 'checked') {{if ($size == '1') {print "please specify a group size";}
    else {if(
    $size == '2') {$send7 mail($from$subject2$auto6);}
    else {if(
    size == '3') {$send8 mail($from$subject2$auto7);}
    else {if(
    size == '4') {$send9 mail($from$subject2$auto8);}
    else {if(
    size == '5') {$send10 mail($from$subject2$auto9);}
    else {if(
    size == '6') {$send11 mail($from$subject2$auto10);}
    }
    }
    }
    }
    }
    }
    }
    }
    if(
    $send2)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send3)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send4)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send5)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send6)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send7)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send8)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send9)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send10)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    if(
    $send11)
    {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    else
    {print 
    "We encountered an error sending your mail, please notify info@myemail.co.uk";}
    }
    }
    }
    function 
    filter_spam ($spam_patterns,$field) {  
    foreach (
    $spam_patterns as $v) {  
    if (
    preg_match("/$v/i",stripslashes($field))) {   
    die(
    "Spam found in input, no email was sent.");  
    }  

    }
    ?>
    Many thanks
    Last edited by seanmarkham; 12-04-2011 at 11:00 AM. Reason: change of coding

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Wrap your code in [ PHP ] (without spaces) tags to preserve formatting - your code is completely unreadable.

  • Users who have thanked BluePanther for this post:

    seanmarkham (12-04-2011)

  • #3
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Thanks or the tip, have added the wrapping,
    let me know where i have gone wrong
    Last edited by seanmarkham; 12-04-2011 at 12:15 PM.

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    There's a couple of things I want you to check:
    PHP Code:
    // Shouldn't these be $_REQUEST['value']?
    $check1 = ['adult_button'];
    $check2 = ['junior_button'];
    $size = ['groupsize']; 
    Also, when you define your fields array, you specify indexes inside { }, it should be ( ). What errors are you getting for this script?

    You should also indent your code a bit better, instead of having it all left justified.

  • #5
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Was unsure if the adult and junior button should be request, I suppose it makes sense asone needs to be specified, when I attempt to submit the form I get an invalid code/unable to access screen. I haven't yet had a problem on other forms I created with the field array but I will use () from now on.
    Now that i have changed the fields to $ _ REQUEST, when i send the form it repeats the following 10 times 'We encountered an error sending your mail, please notify info@myemail.co.uk'
    Last edited by seanmarkham; 12-04-2011 at 11:22 PM.

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    The curly braces could just be an alternate style, dunno. I was always told to use ( ) which is why I suggested it.

    Could you copy paste the exact error please?

  • #7
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts
    ' We encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.ukWe encountered an error sending your mail, please notify info@mysite.co.uk '

    Would it help if i post the code for the form?

  • #8
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    You have a very weird error reporting setup there. I'm pretty sure that if a variable isn't set, and you check for a boolean like you are - if($send1) - it will return false. If you notice, you have 10 error messages there, but 11 send statements. My guess is that one of these sendmail's was successful, but you wouldn't know because the only acknowledgement is a header redirect - which won't work because you've already sent PHP output.

    I would suggest a major rethink about how you're sending your mail. I really don't think you need all those mail function calls. You should build your email based on the user input so that you only need to format 1 mail function. That will make it a lot easier to report errors.

  • #9
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts
    It isn't possible through one mail function though as each one requires a different repsonse.?

  • #10
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    From what I can see, you most certainly can have 1 mail function. Upon reading your code in detail, you're not even using the mail function properly. You're currently sending the emails to the value in $from, instead of the value in $to.

    http://php.net/manual/en/function.mail.php

    The way I would do your processing:
    PHP Code:
    if($check1 == 'checked'){
        switch(
    $size){
            case 
    '1':
                echo 
    'Please specify a group size';
                break;
            case 
    '2':
                
    $body "adults 0 - 8";
                break;
            case 
    '3':
                
    $body "adults 8 - 16";
                break;
            case 
    '4':
                
    $body "adults 16 - 20";
                break;
            case 
    '5':
                
    $body "adults 20 - 44";
                break;
            case 
    '6':
                
    $body "adults 44+";
                break;
        }
    }
    else if(
    $check2 == 'checked'){
        switch(
    $size){
            case 
    '1':
                echo 
    'Please specify a group size';
                break;
            case 
    '2':
                
    $body "juniors 0 - 8";
                break;
            case 
    '3':
                
    $body "juniors 8 - 16";
                break;
            case 
    '4':
                
    $body "juniors 16 - 20";
                break;
            case 
    '5':
                
    $body "juniors 20 - 44";
                break;
            case 
    '6':
                
    $body "juniors 44+";
                break;
        }
    }

    $return mail($to$subject$body);
    if(!
    $return){
        echo 
    'There was a problem sending the mail';


  • Users who have thanked BluePanther for this post:

    seanmarkham (12-05-2011)

  • #11
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts
    That works perfectly, ive managed to add a separate button too that sends me an email if they wish to be added to a mailing list, might look into MySQL in the future.

    Thank you for all your help, very much apprieciated

    Working code below
    PHP Code:
    <?php 
    $to 
    "info@mysite.co.uk";
    $from $_REQUEST['contact_email'];
    $fname $_REQUEST['contact_firstname'];
    $post $_REQUEST['contact_postcode'];
    $address $_REQUEST['contact_address'];
    $lname $_REQUEST['contact_surname'];
    $check1 $_REQUEST['adult_button'];
    $check2 $_REQUEST['junior_button'];
    $size $_REQUEST['groupsize'];
    $data $_REQUEST['mailing_check'];
    $headers "From: $from"
    $subject "Database Entry";
    $subject2 "Kart Racing";


    $fields = array(); 
    $fields{"contact_firstname"} = "First Name:"
    $fields{"contact_surname"} = "Last Name:";
    $fields{"contact_telephone"} = "Phone:";
    $fields{"contact_address"} = "Full Address:";
    $fields{"contact_postcode"} = "Postcode:";
    $fields{"contact_email"} = "Email:"

    $bad_patterns = Array (  
    'b*cc\s*:',  
    'to\s*:',  
    'content\-type',  
    '\[\s*URL.*\]*',
    '\[\s*LINK.*\]*',  
    '\%5B\s*URL.*(\%5D)*',  
    '\%5B\s*LINK.*(\%5D)*',  
    '\[\s*a\s*href.*\]*',  
    '\%5B\s*a\s*href.*(\%5B)*',  
    '\<\s*a\s*href.*\>*',  
    '\%3C\s*a\s*href.*(\%3E)*',  
    'viagra');

    foreach (
    $_REQUEST as $key=>$value) { filter_spam($bad_patterns,$value);}

    $body1 "We have recieved a database entry:\n\n"; foreach($fields as $a => $b)
    {
    $body1 .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);}

    if(
    $fname == '') {print "You have not entered your first name, please go back and try again";}
    else {
    if(
    $lname == '') {print "You have not entered your surname, please go back and try again";}
    else {
    if(
    $from == '') {print "You have not entered an email address, please go back and try again";}
    else {
    if(
    $post == '') {print "You have not entered a postcode, please go back and try again";}
    else {
    if(
    $address == '') {print "You have not entered an address, please go back and try again";}
    else {
    if(
    $check1 == 'checked'){ 
        switch(
    $size){ 
            case 
    '1'
                echo 
    'Please specify a group size'
                break; 
            case 
    '2'
                
    $body "adults 0 - 8"
                break; 
            case 
    '3'
                
    $body "adults 8 - 16"
                break; 
            case 
    '4'
                
    $body "adults 16 - 20"
                break; 
            case 
    '5'
                
    $body "adults 20 - 44"
                break; 
            case 
    '6'
                
    $body "adults 44+"
                break; 
        } 

    else if(
    $check2 == 'checked'){ 
        switch(
    $size){ 
            case 
    '1'
                echo 
    'Please specify a group size'
                break; 
            case 
    '2'
                
    $body "juniors 0 - 8"
                break; 
            case 
    '3'
                
    $body "juniors 8 - 16"
                break; 
            case 
    '4'
                
    $body "juniors 16 - 20"
                break; 
            case 
    '5'
                
    $body "juniors 20 - 44"
                break; 
            case 
    '6'
                
    $body "juniors 44+"
                break; 
        } 


    $return mail($from$subject2$body); 
    if(!
    $return){ 
        echo 
    'There was a problem sending the mail'
    }
    else {
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );}
    if(
    $data == 'checked'){mail($to$subject$body1);}
    }
    }
    }
    }
    }
    function 
    filter_spam ($spam_patterns,$field) {  
    foreach (
    $spam_patterns as $v) {  
    if (
    preg_match("/$v/i",stripslashes($field))) {   
    die(
    "Spam found in input, no email was sent.");  
    }  

    }
    ?>
    Last edited by seanmarkham; 12-05-2011 at 12:33 PM.

  • #12
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Can i pick your brains again please BluePanther, i have ammended the sections on my code for the 0 -8, 8-16 categories etc, lets take the adult 0-8 for example, i have changed it to this

    PHP Code:
            case '2'
                
    $body "Thank you for your information request,
                
    Adult Kart Sessions 
    (Minimum Age of 16)

    15 minutes - £20.00p/p
    30 minutes - £35.00p/p
    45 minutes - £45.00p/p
    60 minutes - £50.00p/p

    We are able to mix adult and junior kart sessions, to request a junior pricelist please follow the link below
    www.mysite.co.uk/request_priceguide.php

    With 8 - 16 people you are able to participate in a group event.
    minimum age of 16 years for all group events)

    A typical group event:
    10 lap qualifying followed by a 40 lap race(trophies and live timing) - £55.00p/p

    Quad Bike sessions
    (Minimum Age of 16)

    15 minutes - £35.00p/p
    60 minutes - £50.00p/p

    Paintball sessions
    (Minimum Age of 12)

    3 hour session including 100 paintballs  - £17.50p/p
    3 hour session including 500 paintballs  - £35.00p/p
    6 hour session including 1000 paintballs - £50.00p/p
    Additional paintballs                    - £6.00 per 100 paintballs

    Add ten-pin bowling to your package for an extra £4.00 per person.

    All bookings require a £20.00 non-refundable deposit per person, this can be made by calling the office on 01400 230306"

                break; 
    How can i make the website address be a 'click here' hyperlink

    Many thanks

  • #13
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    You should be able to just wrap it in a tags in the string:
    PHP Code:
    $body "Thank you for your information request,
                
    Adult Kart Sessions 
    (Minimum Age of 16)

    15 minutes - £20.00p/p
    30 minutes - £35.00p/p
    45 minutes - £45.00p/p
    60 minutes - £50.00p/p

    We are able to mix adult and junior kart sessions, to request a junior pricelist please follow the link below
    <a href=\"www.mysite.co.uk/request_priceguide.php\">Price Guide</a>

    With 8 - 16 people you are able to participate in a group event.
    minimum age of 16 years for all group events)..." 
    The slashes won't appear in your email body - it's an escape character to tell PHP to ignore the quote marks.

  • #14
    New Coder seanmarkham's Avatar
    Join Date
    Dec 2011
    Location
    Lincolnshire, England
    Posts
    50
    Thanks
    11
    Thanked 0 Times in 0 Posts
    it just sends the code in the message.

  • #15
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Ah, I forgot you'll have to send the header 'content type' as well. If you plan on including html in all the emails, check if this works (it will also now send the email from the contact email):
    PHP Code:
    <?php  
    $to 
    "info@mysite.co.uk"
    $from $_REQUEST['contact_email']; 
    $fname $_REQUEST['contact_firstname']; 
    $post $_REQUEST['contact_postcode']; 
    $address $_REQUEST['contact_address']; 
    $lname $_REQUEST['contact_surname']; 
    $check1 $_REQUEST['adult_button']; 
    $check2 $_REQUEST['junior_button']; 
    $size $_REQUEST['groupsize']; 
    $data $_REQUEST['mailing_check']; 
    $headers "From: $from\r\n";
    // Added \r\n above, and next line for html emails
    $headers .= "Content-type: text/html\r\n";
    $subject "Database Entry"
    $subject2 "Kart Racing"

    $fields = array();  
    $fields{"contact_firstname"} = "First Name:";  
    $fields{"contact_surname"} = "Last Name:"
    $fields{"contact_telephone"} = "Phone:"
    $fields{"contact_address"} = "Full Address:"
    $fields{"contact_postcode"} = "Postcode:"
    $fields{"contact_email"} = "Email:";  

    $bad_patterns = Array (   
    'b*cc\s*:',   
    'to\s*:',   
    'content\-type',   
    '\[\s*URL.*\]*'
    '\[\s*LINK.*\]*',   
    '\%5B\s*URL.*(\%5D)*',   
    '\%5B\s*LINK.*(\%5D)*',   
    '\[\s*a\s*href.*\]*',   
    '\%5B\s*a\s*href.*(\%5B)*',   
    '\<\s*a\s*href.*\>*',   
    '\%3C\s*a\s*href.*(\%3E)*',   
    'viagra'); 

    foreach (
    $_REQUEST as $key=>$value) {
        
    filter_spam($bad_patterns,$value);


    $body1 "We have recieved a database entry:\n\n";
    foreach(
    $fields as $a => $b){
        
    $body1 .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
    }

    if(
    $fname == '') {
        print 
    "You have not entered your first name, please go back and try again";

    else { 
        if(
    $lname == '') {
            print 
    "You have not entered your surname, please go back and try again";
        } 
        else { 
            if(
    $from == '') {
                print 
    "You have not entered an email address, please go back and try again";
            } 
            else { 
                if(
    $post == '') {
                    print 
    "You have not entered a postcode, please go back and try again";
                } 
                else { 
                    if(
    $address == '') {
                        print 
    "You have not entered an address, please go back and try again";
                    } 
                    else { 
                        if(
    $check1 == 'checked'){  
                            switch(
    $size){  
                                case 
    '1':  
                                    echo 
    'Please specify a group size';  
                                    break;  
                                case 
    '2':  
                                    
    $body "adults 0 - 8";  
                                    break;  
                                case 
    '3':  
                                    
    $body "adults 8 - 16";  
                                    break;  
                                case 
    '4':  
                                    
    $body "adults 16 - 20";  
                                    break;  
                                case 
    '5':  
                                    
    $body "adults 20 - 44";  
                                    break;  
                                case 
    '6':  
                                    
    $body "adults 44+";  
                                    break;  
                            }  
                        }  
                        else if(
    $check2 == 'checked'){  
                            switch(
    $size){  
                                case 
    '1':  
                                    echo 
    'Please specify a group size';  
                                    break;  
                                case 
    '2':  
                                    
    $body "juniors 0 - 8";  
                                    break;  
                                case 
    '3':  
                                    
    $body "juniors 8 - 16";  
                                    break;  
                                case 
    '4':  
                                    
    $body "juniors 16 - 20";  
                                    break;  
                                case 
    '5':  
                                    
    $body "juniors 20 - 44";  
                                    break;  
                                case 
    '6':  
                                    
    $body "juniors 44+";  
                                    break;  
                            }  
                        }  

                        
    $return mail($from$subject2$body$headers);  
                        if(!
    $return){  
                            echo 
    'There was a problem sending the mail';  
                        } 
                        else {
                            
    header"Location: http://www.mysite.co.uk/contact_confirm.php" );
                        }
                        if(
    $data == 'checked'){
                            
    mail($to$subject$body1$headers);
                        } 
                    } 
                } 
            } 
        } 

    function 
    filter_spam ($spam_patterns,$field) {   
        foreach (
    $spam_patterns as $v) {   
            if (
    preg_match("/$v/i",stripslashes($field))) {    
                die(
    "Spam found in input, no email was sent.");   
            }   
        }  

    ?>
    Took the chance to indent your code as well, look how much easier it is to read! PHP is a language that doesn't rely on indentation, but there are plenty that do so it's a very good idea to start it.
    Last edited by BluePanther; 12-06-2011 at 12:28 AM.

  • Users who have thanked BluePanther for this post:

    seanmarkham (12-06-2011)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •