Jump to content

Create a loop, help needed


Recommended Posts

// * * * * * * * *Get all the vars * * * * * * *$name = filter_input(INPUT_POST, 'companyName', FILTER_SANITIZE_SPECIAL_CHARS); $contact = filter_input(INPUT_POST, 'contact', FILTER_SANITIZE_SPECIAL_CHARS);$phone = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_SPECIAL_CHARS);$email_from = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_SPECIAL_CHARS);$invNo = filter_input(INPUT_POST, 'invNO', FILTER_SANITIZE_SPECIAL_CHARS); $queryType = filter_input(INPUT_POST, 'typeOfQueryDropDownBox', FILTER_SANITIZE_SPECIAL_CHARS);$details = filter_input(INPUT_POST, 'details', FILTER_SANITIZE_SPECIAL_CHARS);$generalDetails = filter_input(INPUT_POST, 'generalDetails', FILTER_SANITIZE_SPECIAL_CHARS);$hireRatesCB = filter_input(INPUT_POST, 'hireRatesCB', FILTER_SANITIZE_SPECIAL_CHARS);$supplyRatesCB = filter_input(INPUT_POST, 'supplyRatesCB', FILTER_SANITIZE_SPECIAL_CHARS);$salesmanVistCB = filter_input(INPUT_POST, 'salesmanVistCB', FILTER_SANITIZE_SPECIAL_CHARS);    $email_message = "---------- Customer Details ----------nn";    $email_message .= "Company Name:              ".($name)."n";    $email_message .= "Contact:    ".($contact)."n";    $email_message .= "Phone:                   ".($phone)."n";    $email_message .= "Email:                   ".($email_from)."n";    $email_message .= "---------- Invoice Query ----------"."nn";    $email_message .= "Invoice No/Contract No:         ".($invNo)."n";    $email_message .= "Type of Query:    ".($queryType)."n";    $email_message .= "Details:                   ".($details)."n";    $email_message .= "---------- General Query ----------"."nn";    $email_message .= "Details: ".($generalDetails)."n";    $email_message .= "Request hire rates:      ".($hireRatesCB)."nn";    $email_message .= "Supply catalogues:      ".($supplyRatesCB)."nn";    $email_message .= "Salesman visit:      ".($salesmanVistCB)."nn";    $email_to = "chris.harwood@hotmail.com";    $email_subject = "QUERY form from - " . $name . ", has been filled in.";// Mail Push'Reply-To: '.$email_from."rn" .'X-Mailer: PHP/' . phpversion();mail($email_to, $email_subject, $email_message);  ?> <!-- Confirmation message -->Thank you for contacting us. We will be in touch with you very soon.

Hi all,

On my very basic form http://lannister.info/test/query.html I have a function that creates another invoice query box. It adds _1, _2 etc to the end of the var names.I'm not sure how to capture these additional vars on the PHP end and output them into the e-mail. I image I need to create an array for the vars and check for additional values with a loop? Not sure where to go from here.

 

Many thanks!

Link to post
Share on other sites

you can add form field name like

<input name="foo[]" ........./><input name="bar[]" ........./>

 

so when you add dynamcially forms and submit them each field will be available in $_POST['foo'], $_POST['bar'] which is an array. You can then get those fields and use them.

Link to post
Share on other sites
$invNo = $_POST['invNo'];$queryType = $_POST['typeOfQueryDropDownBox'];$details = $_POST['details'];  $email_message .= "---------- Invoice Query 1 ----------"."n";    $email_message .= "Invoice No/Contract No:         ".($invNo[0])."n";    $email_message .= "Type of Query:    ".($queryType[0])."n";    $email_message .= "Details:                   ".($details[0])."nnn";        $email_message .= "---------- Invoice Query 2 ----------"."n";    $email_message .= "Invoice No/Contract No:         ".($invNo[1])."n";    $email_message .= "Type of Query:    ".($queryType[1])."n";    $email_message .= "Details:                   ".($details[1])."nnn";         $email_message .= "---------- Invoice Query 3 ----------"."n";    $email_message .= "Invoice No/Contract No:         ".($invNo[2])."n";    $email_message .= "Type of Query:    ".($queryType[2])."n";    $email_message .= "Details:                   ".($details[2])."nnn"; 

Yay! Thank you both! Still need to figure how to make a loop to spit the different queries in the e-mail, but this has been a great help :)

Link to post
Share on other sites
$invNo = $_POST['invNo'];$queryType = $_POST['typeOfQueryDropDownBox'];$details = $_POST['details'];  $email_message .= "---------- Invoice Query 1 ----------"."n";    $email_message .= "Invoice No/Contract No:         ".($invNo[0])."n";    $email_message .= "Type of Query:    ".($queryType[0])."n";    $email_message .= "Details:                   ".($details[0])."nnn";        $email_message .= "---------- Invoice Query 2 ----------"."n";    $email_message .= "Invoice No/Contract No:         ".($invNo[1])."n";    $email_message .= "Type of Query:    ".($queryType[1])."n";    $email_message .= "Details:                   ".($details[1])."nnn";         $email_message .= "---------- Invoice Query 3 ----------"."n";    $email_message .= "Invoice No/Contract No:         ".($invNo[2])."n";    $email_message .= "Type of Query:    ".($queryType[2])."n";    $email_message .= "Details:                   ".($details[2])."nnn"; 

Yay! Thank you both! Still need to figure how to make a loop to spit the different queries in the e-mail, but this has been a great help :)

 

 

 

probably something like

for($i = 0, $l = count($invNo); $i < $l; $i++){  $email_message .= "---------- Invoice Query " . ($i + 1) + " ----------" . "n";  $email_message .= "Invoice No/Contract No: " . ($invNo[$i]) . "n";  $email_message .= "Type of Query: " . ($queryType[$i]) . "n";  $email_message .= "Details: " . ($details[$i]) . "nnn";}
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...