LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP form-trouble adding extra fields (https://www.linuxquestions.org/questions/programming-9/php-form-trouble-adding-extra-fields-366257/)

fdlx4000 09-23-2005 09:09 AM

PHP form-trouble adding extra fields
 
I am a Linux Newbie. I found a canned PHP script for a email form/contact form. I wanted to add extra text fields (city, state, zip, phone, etc.) and did. Everything shows up when I view the form in my browser. But when I send it and check my email for the information that was submitted, the only information that appears is the original fields that came with the script, not the extra fields I added.

I added the fields in my contact.php code but I didn't change anything in the sendeail.php script (wouldn't know where to start).

Can anyone share some wisdom?

david_ross 09-23-2005 01:26 PM

Welcome to LQ.

I'm sure a few of us could share some wisdom but we aren't mind readers. If you post the scripts we'll take a look.

MicahCarrick 09-23-2005 03:03 PM

the fields you added were to teh html. You will have to edit the sendemail.php script as well. In that file you will find variables such as $_POST['firstName'] or $HTTP_POST_VARS['firstName'] where 'name' would be the name of the field you added to the HTML using something like <input type=text name=firstName>. The text of the email will be generated by inserting this "POST" variables where they belong in string of text. If you read through teh script, you'll most likely see where and how it is being done.

As david_ross said, posting the code will get you a response containing exactly what to edit.

fdlx4000 09-23-2005 09:24 PM

Here's the scripts
 
Here are the scripts. The contact.php first, then the sendeail.php. Thanks!!!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email Form </title>
</head>
<body>

<form method="post" action="sendeail.php">

<!-- DO NOT change ANY of the php sections -->
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


Your Name: <br />
<input type="text" name="visitor" size="35" />
<br />
Your Email:<br />
<input type="text" name="visitormail" size="35" />
<br /> <br />
School: <br />
<input type="text" name="visitorschool" size="35" />
<br /> <br />
Can we send you updates? No<input name="no" type="radio" value="no" /> Yes<input checked="checked" name="yes" type="radio" value="yes" /> <br />

<br />
Your Title:<br />
<select name="attn" size="1">
<option value=" Teacher ">Teacher </option>
<option value=" Administrator ">Administrator </option>
<option value=" Parent ">Parent </option>
<option value=" Homeschooler ">Homeschooler </option>
<option value=" Student ">Student </option>
<option value=" Other ">Other </option>

School: <br />
<input type="text" name="school" size="35" />
<br />
Address: <br />
<input type="text" name="address" size="35" />
<br />
City: <br />
<input type="text" name="city" size="35" />
<br />
State: <br />
<input type="text" name="state" size="35" />
<br />
Zip Code: <br />
<input type="text" name="zipcode" size="35" />
<br />
Phone: <br />
<input type="text" name="phone" size="35" />
<br />

</select>
<br /><br />
Comment:
<br />
<textarea name="notes" rows="4" cols="40"></textarea>
<br />
<input type="submit" value="Send Mail" />
<br />
Free Code at: <a href="http://www.ibdhost.com/contact/">ibdhost.com/contact/</a>
</form>

</body>
</html>


______________


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>

<!-- Required: YOUR email ($myemail). Optional: Enter CC email address ($ccx)
Required: Add the link for the 'next page' (at the bottom) -->

<?php

$myemail = "keith@spirit2spirit-i.com";
$ccx = "";

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}
echo $badinput;

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn . "(" . $ccopy . ")" ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";

if (($ccopy == "ccyes") && ($visitormail != ""))
mail($visitormail, $subject, $message, $from);

if ($myemail != "")
mail($myemail, $subject, $message, $from);

if ($ccx != "")
mail($ccx, $subject, $message, $from);

?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="http://www.spirit2spirit-i.com"> Next Page </a>
</p>

</body>
</html>

wilmo2 09-24-2005 03:00 AM

How you modify the the sendeail.php is dependent upon how you want the data submitted from the form to be used. In this case, I suspect from the fields you added that you just want them in the body of the email sent.
The form data from contact.php will be submitted to sendeail.php to process.
Simply, reference the variables in the sendeail.php script with a prepended '$', ie. $phone. Use the formatted output that is already there as a guide.

(Although, like Micah, I prefer to use the $_POST['phone'],$_GET['phone'],$_REQUEST['phone'] methods.
Which I believe is configured in you php.ini file, not sure how. I have always had to call my variables this way)


You have a error in your html, and this will cause all sorts of oddities. In this case you won't
be able to see your inputs on your form.
Code:

...
School: <br />
<input type="text" name="school" size="35" />
<br />
Address: <br />
<input type="text" name="address" size="35" />
<br />
City: <br />
<input type="text" name="city" size="35" />
<br />
State: <br />
<input type="text" name="state" size="35" />
<br />
Zip Code: <br />
<input type="text" name="zipcode" size="35" />
<br />
Phone: <br />
<input type="text" name="phone" size="35" />
<br />

</select>
...

should be

Code:

...
</select> 

School: <br />
<input type="text" name="school" size="35" />
<br />
Address: <br />
<input type="text" name="address" size="35" />
<br />
City: <br />
<input type="text" name="city" size="35" />
<br />
State: <br />
<input type="text" name="state" size="35" />
<br />
Zip Code: <br />
<input type="text" name="zipcode" size="35" />
<br />
Phone: <br />
<input type="text" name="phone" size="35" />
<br />
...

Notice you were closing your select around your other inputs rather than just its options.

From looking at your script, I'm have no idea how this will send email. So if you need to do that
there is a PEAR module to help you with this:
http://pear.php.net/manual/en/package.mail.mail.send.php

Good Luck.

fdlx4000 09-24-2005 07:49 AM

Thanks Wilmo2! This is very helpful. I am a pure novice, I mainly work on the creative side but have the need to learn some common things like doing an email form. I appreciate you and Micah's help. I'll give this a go.

david_ross 09-24-2005 09:27 AM

You will also need to add your extra variables to $message at around line 35.


All times are GMT -5. The time now is 11:41 AM.