plzhelpme Posted May 8, 2010 Share Posted May 8, 2010 Ok, I imagine this is pretty simple but I've tried everything I know and can't figure it out. What I want to be able to do is have a form with a field for First and Last name, then have the email send like: Name: FIRST LAST instead of First Name: FIRST Last Name: LAST I've tried this : $fields{"first";"last"} = "Name"; AND $fields{"first"};{"last"} = "Name"; $fields{"first"},{"last"} = "Name"; $fields{"first"} {"last"} = "Name"; Nothing is working... similarly I will be using 3 separate fields for a phone number (area code, first 3, last 4) and want to accomplish the same thing with that. Please help! Thanks Link to comment https://forums.phpfreaks.com/topic/201120-first-and-last-name-with-one-array/ Share on other sites More sharing options...
phpSensei Posted May 8, 2010 Share Posted May 8, 2010 Not sure what you mean but <?php $name_first = $_POST['firstname']; $name_last = $_POST['lastname']; $full_name = $name_first . " " . $name_last; ?> Link to comment https://forums.phpfreaks.com/topic/201120-first-and-last-name-with-one-array/#findComment-1055149 Share on other sites More sharing options...
plzhelpme Posted May 8, 2010 Author Share Posted May 8, 2010 Hmm... ok, here's the full code i'm using -- how do I change it to add what you suggested? <?php $from = $_REQUEST['email'] ; $fields = array(); $fields{"first"} ;{"last"} = "Name"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } mail( "[email protected]", "New Reservation", $body, "From: $from" ); header( "Location: confirm.php" ); ?> Link to comment https://forums.phpfreaks.com/topic/201120-first-and-last-name-with-one-array/#findComment-1055150 Share on other sites More sharing options...
phpSensei Posted May 8, 2010 Share Posted May 8, 2010 Hmm... ok, here's the full code i'm using -- how do I change it to add what you suggested? <?php $from = $_REQUEST['email'] ; $fields = array(); $fields{"first"} ;{"last"} = "Name"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } mail( "[email protected]", "New Reservation", $body, "From: $from" ); header( "Location: confirm.php" ); ?> Judging from your script you have not retrieved the FIRST and LASTNAME from the form in the first place. the $fields variable is an empty array, what you ment to do is make 2 variables like I have in my script, and get the HTTP POST VARS/HTTP GET VARS using the $_GET or $_POST method. In this case you need the $_POST vars... so do something like this $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; To combine these two into 1 string you can use the "." dot operator between the variables like I did in my script. Review the script I posted and make changes based on that.. Link to comment https://forums.phpfreaks.com/topic/201120-first-and-last-name-with-one-array/#findComment-1055154 Share on other sites More sharing options...
plzhelpme Posted May 8, 2010 Author Share Posted May 8, 2010 Well... this is currently working fine: (first and last are the names of the fields on the form for First Name and Last Name) <?php $from = $_REQUEST['email'] ; $fields = array(); $fields{"first"} = "First Name"; $fields{"last"} = "Last Name"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } mail( "[email protected]", "New Reservation", $body, "From: $from" ); header( "Location: confirm.php" ); ?> All I want is to have first and last name on one line instead of separated... But if I use your example and do $firstname = $_POST['first']; $lastname = $_POST['last']; $full_name = $name_first . " " . $name_last; How do I change the body variable below to include this in the e-mail? $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } Link to comment https://forums.phpfreaks.com/topic/201120-first-and-last-name-with-one-array/#findComment-1055156 Share on other sites More sharing options...
kenrbnsn Posted May 9, 2010 Share Posted May 9, 2010 It looks like you're using some sort of template system, since the statement <?php $fields{"first"} ;{"last"} = "Name"; ?> is not a valid PHP statement. Are you using Smarty? Ken Link to comment https://forums.phpfreaks.com/topic/201120-first-and-last-name-with-one-array/#findComment-1055246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.