PDA

View Full Version : Form Problem


mlowery
10-07-2002, 11:47 PM
hey, I am making a form processor in php. It all works fine except for one thing. Whenever I receive the email with the form contents in it, it doesn't show the words that were typed into the form. Heres the script...

<?
$to = "badm127@hotmail.com";
$comments = "n12br($Comments)";
$contents = "Name ::: $Name
Email Address ::: $Email
Site Name ::: $Site_Name
Site URL ::: $Site_URL
Comments ::: $Comments";
if($contents != "")
{
mail($to, $message, $contents);
echo '<meta http-equiv="refresh" content="2;URL=http://mlowery.nirmani.net/mlowery/confirm.php">';
}
else
{
print("<HTML><BODY><Center><B>ERROR</B><Br>There was an error while processing the application.<BR>You're application was NOT sent.");
print("</BODY></HTML>");
}
?>


The URL to the form is http://mlowery.nirmani.net/mlowery/hosting_form.php

I recieve the email and everything but the email I recieve looks like this...

Name :::
Email Address :::
Site Name :::
Site URL :::
Comments :::

I have used this script before and it worked just fine. Any ideas?

Nightfire
10-08-2002, 12:51 AM
A few things:

$comments = "nl2br($Comments)";

Comments ::: $comments";

You also don't show anything for $message?

Try taking the space out of your form name too.

Looks like your details aren't being collected by the php script, try (I think this is right) somewhere.

$_POST['comments']

mlowery
10-08-2002, 03:35 AM
Ok,
I don't understand what you want me to do with the
$_POST['comments']
The script still will not work.

<?
$To = "badm127@hotmail.com";
$Subject = "Hosting Form Submission"
$Contents = "Name ::: $Name
Email Address ::: $Email
Site Name ::: $Site_Name
Site URL ::: $Site_URL
Comments ::: $Comments";
if($Contents != "")
{
mail($To, $Subject, $Contents);
echo '<meta http-equiv="refresh" content="2;URL=http://mlowery.nirmani.net/mlowery/confirm.php">';
}
else
{
print("<HTML><BODY><Center><B>ERROR</B><Br>There was an error while processing the application.<BR>You're application was NOT sent.");
print("</BODY></HTML>");
}
?>

From what I can see it fits the way that php.net says it should be http://www.php.net/manual/en/function.mail.php
But now it won't even mail. :confused:
Thanks in advance for any more help.

firepages
10-08-2002, 11:35 AM
<?
if($_POST['Submit']){
$headers .='From:<'.$_POST['Email'].">\n";
$headers .='Reply-To:<'.$_POST['Email'].">\n";
$To = "badm127@hotmail.com";
$Subject = "Hosting Form Submission";
$Contents .= 'Name :::'.$_POST['Name']."\n";
$Contents .= 'Email :::'.$_POST['Email']."\n";
$Contents .= 'Site Name :::'.$_POST['Site_Name']."\n";
$Contents .= 'Site URL :::'.$_POST['Site_URL']."\n";
$Contents .= 'Comments :::'.$_POST['Comments']."\n";

if(isset($Contents))
/*
this is pointless as $Contents will always have some value " Name ::: " ...etc
*/
{
mail($To,$Subject,$Contents,$headers);
header("location:http://mlowery.nirmani.net/mlowery/confirm.php");
}
}

print('<HTML><BODY><Center><B>ERROR</B><Br>There was an error while processing the application.<BR>You\'re application was NOT sent.');
print('</BODY></HTML>');
?>

mlowery
10-08-2002, 10:26 PM
I used the exact code. The only thing I editted was the appostrophe in "they're" because I noticed the the apostrophe screwed up the script (but that wasn't the error). It said there was an error on line 19. I looked at line 19 but I don't understand who I would edit it to fix it.
I can't believe that there could be so many problems in such a simple script :(

Galdo
10-08-2002, 10:42 PM
<?
if($_POST['Submit']){
$headers .='From:<'.$_POST['Email'].">\n";
$headers .='Reply-To:<'.$_POST['Email'].">\n";
$To = "badm127@hotmail.com";
$Subject = "Hosting Form Submission";
$Contents .= 'Name :::'.$_POST['Name']."\n";
$Contents .= 'Email :::'.$_POST['Email']."\n";
$Contents .= 'Site Name :::'.$_POST['Site_Name']."\n";
$Contents .= 'Site URL :::'.$_POST['Site_URL']."\n";
$Contents .= 'Comments :::'.$_POST['Comments']."\n";

if(isset($Contents))
/*
this is pointless as $Contents will always have some value " Name ::: " ...etc
*/
{
mail($To,$Subject,$Contents,$headers);
header("location:confirm.php");
}
}

print('<HTML><BODY><Center><B>ERROR</B><Br>There was an error while processing the application.<BR>You're application was NOT sent.');
print('</BODY></HTML>');
?>


Try that.

The forum was screwing up the following line:

header("location:<a href="http://mlowery.nirmani.net/mlowery/confirm.php" target="_blank">http://mlowery.nirmani.net/mlowery/confirm.php</a>");

The <a href="... to _blank"> shouldn't be there, as well as the </a>.

(Note: The code above presumes that confirm.php is in the same directory as this file.)

mlowery
10-09-2002, 03:19 AM
Still another problem! Whenever I click the submit button on the form, the error message in the script pops up. You can see for yourself (The email goes to me). So far this is the script I am using

<?
if($_POST['Submit']){
$headers .='From:<'.$_POST['Email'].">\n";
$headers .='Reply-To:<'.$_POST['Email'].">\n";
$To = "badm127@hotmail.com";
$Subject = "Hosting Form Submission";
$Contents .= 'Name :::'.$_POST['Name']."\n";
$Contents .= 'Email :::'.$_POST['Email']."\n";
$Contents .= 'Site Name :::'.$_POST['Site_Name']."\n";
$Contents .= 'Site URL :::'.$_POST['Site_URL']."\n";
$Contents .= 'Comments :::'.$_POST['Comments']."\n";

if(isset($Contents))
/*
this is pointless as $Contents will always have some value " Name ::: " ...etc
*/
{
mail($To,$Subject,$Contents,$headers);
header("location:confirm.php");
}
}

print('<HTML><BODY><Center><B>ERROR</B><Br>There was an error while processing the application.<BR>The application was NOT sent.');
print('</BODY></HTML>');
?>

I don't understand everything that yall editted into the script or else I would be able to maybe edit it and fix it myself. (I am pretty much a php newbie).

mlowery
10-09-2002, 03:22 AM
BTW: I do have it all in the same directory.

Galdo
10-09-2002, 08:36 PM
<?
if($_POST['Submit']){
$headers .='From:<'.$_POST['Email'].">\n";
$headers .='Reply-To:<'.$_POST['Email'].">\n";
$To = "badm127@hotmail.com";
$Subject = "Hosting Form Submission";
$Contents .= 'Name :::'.$_POST['Name']."\n";
$Contents .= 'Email :::'.$_POST['Email']."\n";
$Contents .= 'Site Name :::'.$_POST['Site_Name']."\n";
$Contents .= 'Site URL :::'.$_POST['Site_URL']."\n";
$Contents .= 'Comments :::'.$_POST['Comments']."\n";

mail($To,$Subject,$Contents,$headers);
header("location:confirm.php");

} else {

print('<HTML><BODY><Center><B>ERROR</B><Br>There was an error while processing the application.<BR>The application was NOT sent.');
print('</BODY></HTML>');
}
?>


Try that.

mlowery
10-09-2002, 11:09 PM
:mad: it still will not work. I am beggining to think that it is the form script itself and not so much the form_processor script. The closest I have gotten to it working is when it mailed to me, but no comments were in the email message. from what I can see...

<input name="Email" type="text" onBlur="MM_validateForm('E- mail','','RisEmail');return document.MM_returnValue">

So that whenever I the information is sent to form_processor.php and the form processor calls for $Email, whatever the user inputted into the "Email" field should show up there. Therefore, whenever I would call for
Email Address ::: $Email and tell it to echo in the email message, it should look like
Email Address ::: person@place.com

I have made a script like this before and it worked just fine. So the only thing I can figure out is that all the other stuff that is included in the Email field tag must screw with the script. But of coarse, I am probably wrong again.

As of now, it still shows the ERROR message and I do not recieve an email message.


Oh yeah... I still cannot figure out what the $_POST is.
Thanks again for any more help.

mordred
10-09-2002, 11:35 PM
MM_validateForm('E- mail','','RisEmail');return document.MM_returnValue

This is Macromedia's JavaScript code. I don't what this function is supposed to do nor how it actually works, but I suspect that it does some kind of validation, like if the field has been filled out or not. Who knows.

Though I don't know if this really is the source of your misbehaving script. I suggest another approach - let's see what gets actually send to the form processing script. You can include this snippet to print you all POST variables that were sent to the script:


<pre>
<?php
var_dump($_POST);
?>
</pre>


Look which value "comments" has and if it gets printed at all. Perhaps your textarea has another name than "comments"? Or your submit variable goes by a wrong name? Or did you forget to add method="post" to your form? Just ideas.

However, the snippet above is good introduction to explaining what $_POST is. It is a predefined variable, more precisely an associative array, that contains all POST variables in your script. It is also superglobal, which means you don't have to import this variable with "global" into a function as with ordinary variables; it's available throughout your whole code.

Here's more info about that one - remember that $_POST is only available in PHP > 4.1 though.
http://us.php.net/manual/en/reserved.variables.php#reserved.variables.post

mlowery
10-10-2002, 03:09 AM
<form name="hosting application" method="post" action="form_processor.php" ENCTYPE="text/plain">
<p>
<input name="Name" type="text" onBlur="MM_validateForm('Name','','R');return document.MM_returnValue">
<font size="2" face="Tahoma"><strong>Name</strong></font> *</p>
<p>
<input name="Email" type="text" onBlur="MM_validateForm('E-mail','','RisEmail');return document.MM_returnValue">
<strong><font size="2" face="Tahoma">E-Mail</font></strong>
*</p>
<p>
<input name="Site_Name" type="text" onBlur="MM_validateForm('Site Name','','R');return document.MM_returnValue">
<strong><font size="2" face="Tahoma">Site Name *</font></strong></p>
<p>
<input name="Site_URL" type="text" onBlur="MM_validateForm('Site URL','','R');return document.MM_returnValue" value="http://">
<strong><font size="2" face="Tahoma">URL of Site to be reviewed
* </font></strong></p>
<p>
<textarea name="Comments" cols="50" rows="10">Type any comments you have or any additional
information you think we should know.</textarea>
</p>
<p>
<input name="Submit" type="submit" value="Submit">


That is the form script. Yeah...
MM_validateForm('E- mail','','RisEmail');return document.MM_returnValue validates that everything was filled in right. I checked everything and still cannot find problem. And that snippet you gave me doesn't work either. I do think that it is that Java script that is messing with the php.

mordred
10-10-2002, 08:07 AM
What means "doesn't work"? You get any errors while using it, and if so, which? Maybe your PHP installation is so old that it doesn't understand $_POST?

Also, JavaScript doesn't interfer with the PHP script... it may only be manipulating the content of the form fields before it gets submitted. Still hard to say, because we do not know the content of this MM_validateForm function.

Just one thing that seems unusual to me: Why do you have ENCTYPE="text/plain" set?

mlowery
10-11-2002, 03:57 AM
Thanks guys.
I decided to go with my old script. The problem was ENCTYPE="text/plain" in the <form> tag. To see it in action go to
http://www.empiregaming.net/hosting/hosting_form.php
Thanks again.