Skip navigation
Currently Being Moderated

Creating php file

Mar 19, 2013 6:52 AM

http://www.milesmemorials.com/estimator.html

 

Im trying created a php file (estimate-to-email.php) to go with this page so that all the information that is selected including the values of those selections is sent in an email. BUT! Im not sure how to collect the informations in the sections that only calculate if chosen for example - The 'Additional services' just created, 'Burial' (plus all the info within this section) and 'Cremation' (again plus all the info within this section)?

 

This is what ive created so far. (ive left out the sections that im not sure about)

 

<?php

if(!isset($_POST['submit']))

{

          //This page should not be accessed directly. Need to submit the form.

          echo "error; you need to submit the form!";

}

$CAT_Custom_76922 = $_POST['CAT_Custom_76922'];

$CAT_Custom_00000 = $_POST['CAT_Custom_00000'];

$CAT_Custom_76926 = $_POST['CAT_Custom_76926'];

$CAT_Custom_76924 = $_POST['CAT_Custom_76924'];

$CAT_Custom_76927 = $_POST['CAT_Custom_76927'];

$FirstName = $_POST['FirstName'];

$LastName = $_POST['LastName'];

$EmailAddress= $_POST['EmailAddress'];

$HomeAddress = $_POST['HomeAddress'];

$HomeCity = $_POST['HomeCity'];

$HomeState = $_POST['HomeState'];

$HomeZip = $_POST['HomeZip'];

$HomeCountry = $_POST['HomeCountry'];

$HomePhone = $_POST['HomePhone'];

$CellPhone = $_POST['CellPhone'];

 

 

 

 

//Validate first

if(empty($CAT_Custom_76922)||empty($CAT_Custom_00000)||empty($CAT_Cust om_76926)||empty($CAT_Custom_76924)||empty($CAT_Custom_76927)||empty( $ FirstName)||empty($LastName)||empty($EmailAddress)||empty($HomeAddres s )|empty($HomeCity)|empty($HomeState)|empty($HomeZip)|empty($HomeCount r y)|empty($HomePhone)||empty($CellPhone))

{

    echo "Please make sure all fields are filled in!";

    exit;

}

 

 

if(IsInjected($EmailAddress))

{

    echo "Bad email value!";

    exit;

}

 

 

$email_from = '$EmailAddress';//<== update the email address

$email_subject = "Estimate from M&D website";

$email_body .= "Name: $FirstName.\n";

$email_body .= "Surname: $LastName.\n";

$email_body .= "Address: $HomeAddress.\n";

$email_body .= "City: $HomeCity.\n";

$email_body .= "County: $HomeState.\n";

$email_body .= "Postcode: $HomeZip.\n";

$email_body .= "Country: $HomeCountry.\n";

$email_body .= "Phone: $HomePhone.\n";

$email_body .= "Mob: $CellPhone.\n";

$email_body .= "Removal milage: $CAT_Custom_76922.\n";

$email_body .= "Viewing: $CAT_Custom_00000.\n";

$email_body .= "Coffin: $CAT_Custom_76926.\n";

$email_body .= "Route: $CAT_Custom_76924.\n";

$email_body .= "Limousines: $CAT_Custom_76927.\n";

 

 

 

 

  

$to = "Ness_Rob@yahoo.com";//<== update the email address

$headers = 'From: '.$EmailAddress."\r\n";

$headers .='Reply-To:'.$EmailAddress."\r\n";

//Send the email!

mail($to,$email_subject,$email_body,$headers);

//done.  redirect to payment page.

header('Location: thankyou_estimate.html');

 

 

// Function to validate against any email injection attempts

function IsInjected($str)

{

  $injections = array('(\n+)',

              '(\r+)',

              '(\t+)',

              '(%0A+)',

              '(%0D+)',

              '(%08+)',

              '(%09+)'

              );

  $inject = join('|', $injections);

  $inject = "/$inject/i";

  if(preg_match($inject,$str))

    {

    return true;

  }

  else

    {

    return false;

  }

}

 

?>

 
Replies
  • Currently Being Moderated
    Mar 19, 2013 8:44 AM   in reply to Ness_quick

    You might want to fix this spelling -

     

    please click on thunmbnails to view larger image & description of coffiins

     

    And just to make sure we understand what we are dealing with, adjust the code at the top of the page to this -

     

     

    <?php

    if(!isset($_POST['submit']))

    {

              //This page should not be accessed directly. Need to submit the form.

              exit("error; you need to submit the form!");

    }

    echo "<pre>";exit(print_r($_POST));

     

    Tell me what is printed to the page after you have filled out the form with random choices and then submitted it.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2013 3:06 PM   in reply to Ness_quick

    Then something is wrong with your code. Are you sure the form is submitting to this page?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2013 4:18 AM   in reply to Ness_quick

    No, I meant this -

     

    <form name="catwebformform22057" onsubmit="return checkWholeForm22057(this)" action="/estimate-to-email.php" enctype="multipart/form-data" method="post">

     

    The form is submitting to /estimate-to-email.php - are you sure you made my suggested code addition to that page?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2013 6:42 AM   in reply to Ness_quick

    Change the below which is at the top of your processing script:

     

    if(!isset($_POST['submit']))

     

    {

      //This page should not be accessed directly. Need to submit the form.

    echo "error; you need to submit the form!";

    }

    $CAT_Custom_76922 = $_POST['CAT_Custom_76922'];

     

     

     

    TO THIS:

     

    if(array_key_exists('catwebformbutton', $_POST))

    {

    $CAT_Custom_76922 = $_POST['CAT_Custom_76922'];

     

     

    ADD the closing } at the end of the script as shown below:

     


    return false;

     

      }

     

    }

    }

     

     

    ADD name="catwebformbutton" to the form submit button:(as shown)

     

    <input class="submit" name="catwebformbutton" id="catwebformbutton" type="submit" value="Submit" />

     

     

    AMEND the opening form tag to as below: ie delete - enctype="multipart/form-data"

     

    <form name="catwebformform22057" onsubmit="return checkWholeForm22057(this)" action="/estimate-to-email.php" method="post">

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2013 7:17 AM   in reply to osgood_

    I also forgot to mention that there are spaces in some of the variables name below, which are in the php processing script like; $HomeAddres s -$HomeCount r y -  I don't know if that is as a result of the forum of if there are actually spaces in the original code. If the spaces are in your original code you MUST delete them for the form to work.

     

     

    if(empty($CAT_Custom_76922)||empty($CAT_Custom_00000)||empty($CAT_Cust om_76926)||empty($CAT_Custom_76924)||empty($CAT_Custom_76927)||empty( $ FirstName)||empty($LastName)||empty($EmailAddress)||empty($HomeAddres s )|empty($HomeCity)|empty($HomeState)|empty($HomeZip)|empty($HomeCount r y)|empty($HomePhone)||empty($CellPhone))

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2013 7:24 AM   in reply to osgood_

    I think this is the nefarious work of the forum....

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2013 9:09 AM   in reply to Ness_quick

    Ness_quick wrote:

     

    I checked those spaces but there definatley isn't any. I tried submitting the form but its now coming up with 'Please make sure all fields are filled in!'

     

    C


     

    Well yes, if you dont fill in the fields that you have asked to be validated then you will get that message.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2013 9:12 AM   in reply to Ness_quick

    Ness_quick wrote:

     

    Could this be because of ive not put into the php some of the form, because -

     

    Im not sure how to collect the informations in the sections that only calculate if chosen for example - The 'Additional services', 'Burial' (plus all the info within this section) and 'Cremation' (again plus all the info within this section)?

    Thats the problem, how to isolate those input fields because you obviously want to make sure they have been filled in so if you add those to the php processing script to be validated and they are NOT filled in then the form won't submit.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2013 9:58 AM   in reply to Ness_quick

    Ness_quick wrote:

     

    Is there a way i can do that?

     

    I expect so, but personally I don't know, the form is quite complex. Might be worth starting a new thread or posting in the php forum as well, just to cover all angles. Someone might know. Post on Stackflow as well.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points