Topic: Lame PHP Form Question (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=30818" title="Pages that link to Topic: Lame PHP Form Question (Page 1 of 1)" rel="nofollow" >Topic: Lame PHP Form Question <span class="small">(Page 1 of 1)</span>\

 
Radical Rob
Paranoid (IV) Inmate

From: Lost Angeles Kalifornia, via Hawaii....
Insane since: Jun 2001

posted posted 02-06-2009 06:35

Ok so I have this PHP guru guy that's been helping me trudge through my PHP on my site and he's not available to help me with what I'm assuming is a simple task...

I have a form with a bunch of questions, selectors, drop down menus, etc. http://www.pacificcrownmolding.com/contact2.php

All I'm trying to do is have the email contain all of the content in the form. I figured it would be as easy as...

$this_message = ($_POST['senderName']);
$this_message = ($_POST['senderEmail']);
$this_message = ($_POST['senderAddy']);
$this_message = ($_POST['senderCity']);
$this_message = ($_POST['senderZip']);

But when I do that, it crashes and displays zip. How do I make my email that I receive contain the info from the form? I'm not so much worried about the look of it right now, but eventually I'd like it to format pretty clean.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 02-06-2009 10:48

all but the first = should be .=, since you're appending to the string.

Blaise
Paranoid (IV) Inmate

From: London
Insane since: Jun 2003

posted posted 02-06-2009 11:37

Why doesn't php use += like every other language out there? Or is this a string specific thing?

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 02-06-2009 13:09

this is a string specific thing

twItch^
Maniac (V) Mad Scientist

From: Denver, CO, USA
Insane since: Aug 2000

posted posted 02-06-2009 15:55

yeah, string concatenation is done with a dot between strings. You may also want to through line breaks in after each of the fields "\n" (again, string concatenated) so it won't be one long string.

So, something like...

code:
$this_message = $_POST['senderName'] . "\n";
$this_message .= $_POST['senderEmail'] . "\n";
$this_message .= $_POST['senderAddy'] . "\n";
$this_message .= $_POST['senderCity'] . "\n";
$this_message .= $_POST['senderZip'];



-S

(Edited by twItch^ on 02-06-2009 15:56)

Radical Rob
Paranoid (IV) Inmate

From: Lost Angeles Kalifornia, via Hawaii....
Insane since: Jun 2001

posted posted 02-06-2009 18:57

You guys are sick! I spent all night searching php blogs, php.net, etc. and could not for the life of me figure this out.
I'd make adjustments, try it,break it, fix it, try again...

As usual, beers on me!

Radical Rob
Paranoid (IV) Inmate

From: Lost Angeles Kalifornia, via Hawaii....
Insane since: Jun 2001

posted posted 02-06-2009 19:06

Oh, one last thing... so how would I display the results in the email to look a little nicer?

$this_message = "Name:" $_POST['senderName'] . "\n";
$this_message .= "Email Address:" $_POST['senderEmail'] . "\n";
$this_message .= "Street Address:" $_POST['senderAddy'] . "\n";
$this_message .= "City:" $_POST['senderCity'] . "\n";
$this_message .= "Zip Code:"$_POST['senderZip'];


Is it that simple or will I need to modify it else where? I'd appreciate any links to sites that are a bit more thorough in their explanation of this process.

Thanks!

twItch^
Maniac (V) Mad Scientist

From: Denver, CO, USA
Insane since: Aug 2000

posted posted 02-06-2009 20:09

Anytime you want to glue together two strings, you need the dot.

So...

code:
1. $this_message = "Name: " . $_POST['senderName'] . "\n";



etc.

Note also that inside of double quotes you can pass variables, so you can put it all in one string without concatenation:

code:
2. $this_message = "Name: {$_POST['senderName']}\n";



The double-brackets force PHP to parse the data inside as a variable. Without the brackets, this would not work, as you're using array data (in this case, the $_POST array). If you had to do validation beforehand and eventually pulled that one string of data out into a normal variable, you could just do

code:
3. $this_message = "Name: $senderName\n";



but you don't have to. #2 will work just fine for your purposes. If you want more information, I'm sure a quick google search of "PHP string concatenation" would get you some results.

-S

Radical Rob
Paranoid (IV) Inmate

From: Lost Angeles Kalifornia, via Hawaii....
Insane since: Jun 2001

posted posted 02-06-2009 20:32

You're Awesome... that does the trick. I just needed to know exactly what that was called to search for it.

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 02-07-2009 11:09

if this form is for regular users then please read about email injection or otherwise spammers will use your site to send e-mails to whoever they want...



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu