LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-23-2005, 10:09 AM   #1
fdlx4000
LQ Newbie
 
Registered: Sep 2005
Posts: 3

Rep: Reputation: 0
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?
 
Old 09-23-2005, 02:26 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
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.
 
Old 09-23-2005, 04:03 PM   #3
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
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.
 
Old 09-23-2005, 10:24 PM   #4
fdlx4000
LQ Newbie
 
Registered: Sep 2005
Posts: 3

Original Poster
Rep: Reputation: 0
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>
 
Old 09-24-2005, 04:00 AM   #5
wilmo2
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian,Redhat,Gentoo,Suse,Slackware
Posts: 3

Rep: Reputation: 0
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.
 
Old 09-24-2005, 08:49 AM   #6
fdlx4000
LQ Newbie
 
Registered: Sep 2005
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
Old 09-24-2005, 10:27 AM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a harddrive for extra space fakie_flip Linux - Hardware 5 10-02-2005 09:39 PM
dns adding extra webserver bristi Linux - Networking 0 09-08-2005 06:23 AM
adding extra repositories? KezzerDrix Mandriva 1 04-27-2005 10:55 AM
adding an extra pci slot diversitas Linux - Hardware 1 04-16-2005 03:00 PM
PHP appending form fields and text. BigFred Programming 6 09-19-2003 11:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration