Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

adding additional fields to my mailform

Links for php scripts

Moderators: macek, egami, gesf

adding additional fields to my mailform

Postby lindatash » Mon Apr 12, 2004 11:38 pm

Hi!

I need your help, guys!

I have this PHP mail form that I want to use on my website, but I want to add additional fields to it.
How can I do this? I need to add fields like: your occupation? your profession? your education? your interests? etc...

PLEASE, HELP!

Here is a code:


<?php
error_reporting(0);
define("TO", "Linda <myemail@mywebsite.com>");
include("design.php");
$error_flag = false;
if (sizeof($HTTP_POST_VARS) >= 4) {
$sender_name = $HTTP_POST_VARS['sender_name'];
$sender_mail = $HTTP_POST_VARS['sender_mail'];
$mail_subject = $HTTP_POST_VARS['mail_subject'];
$mail_body = $HTTP_POST_VARS['mail_body'];
if (strlen($sender_name) < 3 || strlen($sender_name) > 40) {
$error_flag = true;
$error_message = "<p class=\"error\"><b><font color=#FC0433>Please, type your name correctly!</font></b></p>";
}
elseif (!eregi("^.+@(.+\.)+.+$", $sender_mail) || strlen($sender_mail) < 8 || strlen($sender_mail) > 40) {
$error_flag = true;
$error_message = "<p class=\"error\"><b><font color=#FC0433>Please, type your e-mail correctly!</font></b></p>";
}
elseif (strlen($mail_subject) < 4) {
$error_flag = true;
$error_message = "<p class=\"error\"><b><font color=#FC0433>What's your subject?</font></b></p>";
}
elseif (strlen($mail_body) < 4) {
$error_flag = true;
$error_message = "<p class=\"error\"><b><font color=#FC0433>What's your message?</font><b></p>";
}
$mail_headers = "Return-Path: ".reserve."\n".
"From: ".$sender_name."<".$sender_mail.">\n".
"Reply-To: ".$sender_name."<".$sender_mail.">\n".
"Content-Type: text/plain; charset=windows-1251\n".
"Content-Transfer-Encoding: 8bit\n".
"Date: " . date("r")."\n".
"X-Mailer: mailer_".$SERVER_NAME;
}
head();

if (empty($sender_name) || $error_flag) : print_mail_form();
elseif (mail(TO, $mail_subject, $mail_body, $mail_headers)) :
?>
<table width="70%" border="0" cellspacing="0" cellpadding="8" class="mail_sended">
<td align=center><b>Your information has been received.<br>Thanks for your interest.</b></td>
</table>
<?php else :
echo ("<p><b>Your message has not been sent.<br>Please, try again or try next time.</b></p>");
$error_message = "";
$error_flag = true;
print_mail_form();
endif;
foot();
function print_mail_form() {
global $error_flag, $error_message, $sender_name, $sender_mail, $mail_subject, $mail_body;
if (empty($sender_name)) $sender_name = "";
if (empty($sender_mail)) $sender_mail = "";
if (empty($mail_subject)) $mail_subject = "";
if (empty($mail_body)) $mail_body = "";
?>
<?php if ($error_flag) echo $error_message;?>
<form method="post" name="mail" id="mail">

<p align=center><b>Please, fill in this form:</p>
<br>
<table border="0" cellspacing="0" cellpadding="1">
<tbody>
<tr><td><b>Full name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><input type="text" name="sender_name" id="sender_name" value="<? echo htmlspecialchars($sender_name);?>" size="32" maxlength="60"></td></tr>
<tr><td><b>E-mail address:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><input type="text" name="sender_mail" id="sender_mail" value="<? echo htmlspecialchars($sender_mail);?>" size="32" maxlength="60"></td>
</tr>
<tr><td><b>Subject:&nbsp;&nbsp; <b><input type="text" name="mail_subject" id="mail_subject" value="<? echo htmlspecialchars($mail_subject);?>" size="12"></td></tr>
<tr><td><b>Message:&nbsp;&nbsp;&nbsp;&nbsp;</b><textarea cols="27" rows="2" name="mail_body" id="mail_body" id="mail_body"><? echo htmlspecialchars($mail_body);?>
</textarea></td></tr>
<tr><td align=right><input type="submit" value="Send"></td></tr>
</tbody>
</table>
</form>
<?php }?>

</p>
</td></tr></table>



This form works perfectly! I just need to add more questions (fields) to it and I want them to come in the body of the e-mail with the name of that field and the answer of the user - so it could be convenient to read.

I would also need to add uploading a photo function in this form, but I guess that would be toooooo complicated.

Thanks in advance for your help!

Sincerely,
Linda
lindatash
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Apr 12, 2004 11:23 pm

Postby Alex » Wed Apr 14, 2004 6:26 am

You would need to edit your initial html form under the <form> tag
use <input> statements to get more input fields for your data....

Seriously though you should go and read PHP manual from http://www.php.net/manual/en/. Focus on chapters I, II, IV, and some of V and you will be able to not only add something to somebody elses code, but better yet develop your own. I can tell that you could not have writtent the code that you posted since if you did you would not be asking that sort of question that is described in the first or second chapter in any PHP manual...

[/code]
Alex
New php-forum User
New php-forum User
 
Posts: 180
Joined: Fri Mar 07, 2003 4:59 pm

Postby lindatash » Wed Apr 14, 2004 11:04 am

Thanks, Alex!
Of course, I didn't write this code, if I could I would ask so silly questions. Thanks for your advice again.

Linda.
lindatash
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Apr 12, 2004 11:23 pm

Postby Alex » Wed Apr 14, 2004 4:00 pm

Well I don’t want to discourage you from learning PHP, it a great great language... if you want, post the add on fields that you need to be added to the application and maybe what you want some of them to do, and we can help you rewrite the code to sooth your needs. I'm not a mean kid I just want to show you the better of the two ways to do this type of thing (meaning that if you continue with php you can create wonderful things). I not at all wanted you to get disappointed in this forum or language, and if I did I apologize....

If you want, you can send me an email, and when I have some free time, ill go over the code and write you comments on what each line does along with how the code works all together to help you understand it.

My email is: alexander@russianct.com or if you have AIM, you can contact me through there, my screen name is RusK75.

Take it easy!
Alex
Alex
New php-forum User
New php-forum User
 
Posts: 180
Joined: Fri Mar 07, 2003 4:59 pm

Postby lindatash » Wed Apr 14, 2004 7:36 pm

Thanks, Alex. I've already got settled with this form - I was told how to add additional fields so they could be sent to me by email - now it works great. Thank again for your wish to help! Linda.
lindatash
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Apr 12, 2004 11:23 pm


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.