Jump to content

First and Last name with one array


plzhelpme

Recommended Posts

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

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" );

?>

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..

 

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]); }

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.