Glad to help.
Since this issue is now resolved, please mark the thread as Resolved to communicate to other members that this is no longer pending.
Glad to help.
Since this issue is now resolved, please mark the thread as Resolved to communicate to other members that this is no longer pending.
- Josh
So, it didn't seem to work - also, something I am noticing is that even if someone clicks on Landscape Design and Construction AND Lighting, only lighting shows up in the email...
Actually, if I didn't hit lighting this shows up (along with what I had before)
Services: $0 - $500
Budget: $0 - $500
I apologize for being a pain in the ass.
Last edited by katiebugla; 08-26-2011 at 03:24 PM.
Will that read? I basically need it to read as such:PHP Code:<?php
$to = "josh@gscapedesign.com";
$subject = "Greenscape Customer Inquiry";
$message = "Customer name: " . $_POST['name'] . "\r\n" .
"Phone number: " . $_POST['phone'] . "\r\n" .
"Email: " . $_POST['email'] . "\r\n" ."\r\n" .
"Best Way to Contact: " . $_POST['contact'] . "\r\n" ."\r\n";
$field = array('landscape design and construction', 'hardscape design and construction', 'grounds maintenance', 'irrigation and drainage systems', 'lighting');
foreach($field as $f) {
if($_POST[$f] != '' && isset($_POST[$f])) {
$message .= "Services: ".$_POST[$f]."\r\n";
}
}
$message .= "Budget: " . $_POST['budget'] . "\r\n" .
$message .= "Anything Else: " . $_POST['other'] . "\r\n" .
$from = $_POST['email'];
$headers = "From: $from" . "\r\n";
$headers = "Bcc: kroge16@tigers.lsu.edu" . "\r\n" ;
mail($to,$subject,$message,$headers) ;
?>
Customer name: Katie
Phone number: 1-555-555-5555
Email: katiebugla@yahoo.com
Best Way to Contact: Phone
Budget: $0-500
Services: lighting, grounds maintenance
Anything Else: "I like your portfolio page." (text area)
You're right, it didn't parse the field names correctly. But I had a better, more elegant solution.
Let's rename all of the checkboxes to the same name, as an array. The[]will indicate that it is an array. Change your checkboxes to this:
Code:<label> <input name="serviceItem[]" type="checkbox" id="landscape design and construction" value="landscape design and construction" /> <span class="form_text">Landscape Design & Construction</span></label> <br /> <label> <input name="serviceItem[]" type="checkbox" id="hardscape design and construction" value="hardscape design and construction" /> <span class="form_text">Hardscape Design & Construction</span></label> <br /> <label> <input name="serviceItem[]" type="checkbox" id="grounds maintenance" value="grounds maintenance" /> <span class="form_text">Grounds Maintenance</span></label> <br /> <label> <input name="serviceItem[]" type="checkbox" id="irrigation and drainage systems" value="irrigation and drainage systems" /> <span class="form_text">Irrigation & Drainage Systems</span></label> <br /> <label> <input name="serviceItem[]" type="checkbox" id="lighting" value="lighting" /> <span class="form_text">Lighting</span></label>
We then loop through the serviceItem if it is set, and then append each value to$message
Here's the PHP:
The result would be like this:PHP Code:$to = "josh@gscapedesign.com";
$subject = "Greenscape Customer Inquiry";
$message = "Customer name: " . $_POST['name'] . "\r\n" .
"Phone number: " . $_POST['phone'] . "\r\n" .
"Email: " . $_POST['email'] . "\r\n" ."\r\n" .
"Contact: " . $_POST['contact'] . "\r\n" ."\r\n";
$field = array('landscape design and construction', 'hardscape design and construction', 'grounds maintenance', 'irrigation and drainage systems', 'lighting', 'budget');
if(isset($_POST[serviceItem])) {
if(isset($_POST[serviceItem])) {
$message .= "Services: ".implode(", ", $_POST[serviceItem])."\r\n";
}
}
$message .= "Budget: " . $_POST['budget'] . "\r\n" .
$from = $_POST['email'];
$headers = "From: $from" . "\r\n";
$headers = "Bcc: kroge16@tigers.lsu.edu" . "\r\n" ;
mail($to,$subject,$message,$headers) ;
This code also gives you much more flexibility, because you can add/remove checkboxes easily without having to modify your PHP code. Any additional checkboxes should have the name set toCode:Customer name: Katie Phone number: 1-555-555-5555 Email: katiebugla@yahoo.com Best Way to Contact: Phone Budget: $0-500 Services: lighting, grounds maintenanceserviceItem[].
I tested this out myself this time and it works.
- Josh
katiebugla (08-26-2011)
Btw, I edited that last post. I didn't realize you wanted it like "Services: lighting, etc." The new code should do that.
- Josh
I am going to test it again... just out of curiousity, does 'budget' need to be in the array?
No problem. Also, this is dead code, I forgot to remove it:
You can go ahead and erase that line. It doesn't do anything anymore. And budget didn't need to be in the array to begin with, but somehow my absent-minded self put it in there. :PPHP Code:$field = array('landscape design and construction', 'hardscape design and construction', 'grounds maintenance', 'irrigation and drainage systems', 'lighting', 'budget');
- Josh
I've done so many test runs at this point I can't tell which test went with which trail, but the latest outcome (email side):
Customer name: Katie
Phone number: 1-XXX-XXX-XXXX
Email: katiebugla@yahoo.com
Contact: Phone
Anything Else: Another test.
katiebugla@yahoo.comBudget: $0 - $500
Customer name: Katie
Phone number: 1-XXX-XXX-XXXX
Email: katiebugla@yahoo.com
Contact: Phone
Can you post your entire code that you're using (PHP + HTML)?
Something must be wrong.
- Josh
Bookmarks