Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP contact form. Need additional fields.
Old 12-31-2005, 12:21 PM PHP contact form. Need additional fields.
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
First and foremost, Happy New Year to all!

Secondly, I have a PHP contact form which I will be implementing into my website. It asks for name, email, and comments. I would like to add address and telephone number. I am a total PHP novice. Can someone provide me with this type of contact form? I would be most appreciative. Can you please help me?

Thank you and have a nice day!
Robert_R is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-31-2005, 08:38 PM
TrentonD's Avatar
Ultra Talker

Posts: 253
Location: Calgary, Alberta, Canada
Trades: 0
Here is a contact form that I use on my websites, just modified a bit.

HTML Code:
<form name="CHANGE" method="post" action="CHANGE">
<table width="90%" cellspacing="1" cellpadding="1" border="0">
    <tr>
        <td width="25%" align="right">
            Name:
        </td>
        <td width="75%">
            <input name="hname" type="text" id="name">
        </td>
    </tr>
    <tr>
        <td width="25%" align="right">
            E-Mail:
        </td>
        <td width="75%">
            <input name="email" type="text" id="email">
        </td>
    </tr>
    <tr>
        <td width="25%" align="right">
            Address 1:
        </td>
        <td width="75%">
            <input name="email" type="text" id="email">
        </td>
    </tr>
    <tr>
        <td width="25%" align="right">
            Address 2:
        </td>
        <td width="75%">
            <input name="email" type="text" id="email">
        </td>
    </tr>
    <tr>
        <td width="25%" align="right">
            Phone Number:
        </td>
        <td width="75%">
            <input name="email" type="text" id="email">
        </td>
    </tr>
    <tr>
        <td width="25%" align="right">
            Comments:
        </td>
        <td width="75%">
            <textarea name="problem" id="problem" rows="5" cols="25"></textarea>
        </td>
    </tr>
    <tr>
        <td width="25%" align="right">
        </td>
        <td width="75%">
            <input type="submit" value="Submit">
            <input type="reset" value="Reset">
        </td>
    </tr>
</table>
</form>
If you have any questions or comments, please feel free to let me know!
__________________
Signature Coming Soon! :)
Please login or register to view this content. Registration is FREE
TrentonD is offline
Reply With Quote
View Public Profile Visit TrentonD's homepage!
 
Old 01-01-2006, 10:34 PM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
Thanks. I appreciate it.
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-01-2006, 10:42 PM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
OK. I have the form done and I'd wish for the user to be directed to an error page if the required fields aren't filled in. And to a thank you page if they've filled out the form successfully.

But, that code doesn't seem to be working. Can someone give me a hand?

Here's the code in question. My question refers to the code which is in BOLD

<?php

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "me@example.com";
$Subject = Trim(stripslashes($_POST['Subject']));
$Name = Trim(stripslashes($_POST['Name']));
$Address = Trim(stripslashes($_POST['Address']));
$Telephone = Trim(stripslashes($_POST['Telephone']));

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Subject)=="") $validationOK=false;
if (Trim($Address)=="") $validationOK=false;
if (Trim($Telephone)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv="refresh" content="0;URL=http://www.example.com/error.htm">";


exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, $Name, $Address, $Telephone "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "<meta http-equiv="refresh" content="0;URL=http://www.example.com/thankyou.htm">";
}
else{
print "<meta http-equiv="refresh" content="0;URL=http://www.example.com/error.htm">";
}

?>
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-01-2006, 10:56 PM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
Quick and important question before anyone starts answering. My site is not live yet I'm testing it offline on my own computer.

When I reach the aforementioned error or thank you page what happens is my PHP code displays. As opposed to the corresponding html pages which the PHP code is supposed to take you to.

I hope I typed that correctly.

Testing the code on my computer I get the PHP code not the error or thank you page.
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-02-2006, 02:12 AM
stOx's Avatar
Machine

Latest Blog Post:
Worlds Smallest Car - Peel P50
Posts: 2,111
Name: Matt. (>',')>
Location: London, England.
Trades: 0
You get the code displayed in your browser?
Do you have php installed on your computer?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
stOx is offline
Reply With Quote
View Public Profile Visit stOx's homepage!
 
Old 01-02-2006, 09:51 AM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
Quote:
Originally Posted by stOx
You get the code displayed in your browser?
Do you have php installed on your computer?
Yes. It displays the code for the error or thankyou page as opposed to the actual page. As I mentioned this is testing offline.

Is there a sure fire way to check if PHP is installed on my computer?

Thanks.
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-02-2006, 10:12 AM
stOx's Avatar
Machine

Latest Blog Post:
Worlds Smallest Car - Peel P50
Posts: 2,111
Name: Matt. (>',')>
Location: London, England.
Trades: 0
The sure fire way to know if PHP is installed is if you can remember installing it.

Have you installed apache or anything similar? Do any other php scripts run on your computer?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
stOx is offline
Reply With Quote
View Public Profile Visit stOx's homepage!
 
Old 01-02-2006, 10:20 AM
Skilled Talker

Posts: 70
Trades: 0
The easiest way to check if php is installed is to write the following code in a text editor:

<?php
phpinfo();
?>

Save this in your root web directory as 'phpinfo.php'. Then load up your browser and goto http://<mydomain>/phpinfo.php
If you get a page stating a heap of configuration variables, you're all set. If not, then php isn't properly configured on your computer.

As for the form validation, I would use this code. If there's an incorrect form parameter, the user is redirected to the error page instantly.

PHP Code:
// Captures the form variables, saves you writing out each and every variable :)
foreach($_POST as $key => $val) {
$
$key trim(stripslashes($val));
}
/* Validates the form data. Because every field is required, you can use another loop to save time coding */
foreach($_POST as $key => $val) {
$empty "";
if(
$val == $empty) {
header("Location: http://www.example.com/error.htm");
exit();
}
}
 
// prepare email body text
$Body "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";

// send email 
$success mail($EmailTo$Subject$Body$Name$Address$Telephone "From: <$EmailFrom>");
 
if(
$success) {
header("Location: http://www.example.com/thankyou.htm");
exit();
} else {
header("Location: http://www.example.com/error.htm");
exit(); 
I would suggest that you use PHP sessions on all the pages concerning the email form as it's much easier to transfer data between pages .
cerebro89 is offline
Reply With Quote
View Public Profile
 
Old 01-03-2006, 08:30 AM
Average Talker

Posts: 28
Trades: 0
here is my code contact.
look it :
http://t4vn.net/index.php?do=contact
if you like it,please post here.I will share my code to you.
__________________

Please login or register to view this content. Registration is FREE
==>PHP Tutorials,PHP Example,PHP Script,Online Project,PHP News,....and more,helper coding...

Please login or register to view this content. Registration is FREE
==>Dog Information
t4vn.net is offline
Reply With Quote
View Public Profile
 
Old 01-03-2006, 08:56 AM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
Quote:
Originally Posted by cerebro89
The easiest way to check if php is installed is to write the following code in a text editor:

<?php
phpinfo();
?>

Save this in your root web directory as 'phpinfo.php'. Then load up your browser and goto http://<mydomain>/phpinfo.php
If you get a page stating a heap of configuration variables, you're all set. If not, then php isn't properly configured on your computer.

As for the form validation, I would use this code. If there's an incorrect form parameter, the user is redirected to the error page instantly.

PHP Code:
// Captures the form variables, saves you writing out each and every variable :)
foreach($_POST as $key => $val) {
$
$key trim(stripslashes($val));
}
/* Validates the form data. Because every field is required, you can use another loop to save time coding */
foreach($_POST as $key => $val) {
$empty "";
if(
$val == $empty) {
header("Location: http://www.example.com/error.htm");
exit();
}
}
 
// prepare email body text
$Body "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";

// send email 
$success mail($EmailTo$Subject$Body$Name$Address$Telephone "From: <$EmailFrom>");
 
if(
$success) {
header("Location: http://www.example.com/thankyou.htm");
exit();
} else {
header("Location: http://www.example.com/error.htm");
exit(); 
I would suggest that you use PHP sessions on all the pages concerning the email form as it's much easier to transfer data between pages .
Thank you very much I appreciate it.
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-03-2006, 08:57 AM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
Quote:
Originally Posted by t4vn.net
here is my code contact.
look it :
http://t4vn.net/index.php?do=contact
if you like it,please post here.I will share my code to you.
Yes it looks excellent and interesting. Please post it.

Thank you very much!
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-04-2006, 09:57 PM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
Quote:
Originally Posted by cerebro89
As for the form validation, I would use this code. If there's an incorrect form parameter, the user is redirected to the error page instantly.

PHP Code:
// Captures the form variables, saves you writing out each and every variable :)
foreach($_POST as $key => $val) {
$
$key trim(stripslashes($val));
}
/* Validates the form data. Because every field is required, you can use another loop to save time coding */
foreach($_POST as $key => $val) {
$empty "";
if(
$val == $empty) {
header("Location: http://www.example.com/error.htm");
exit();
}
}
 
// prepare email body text
$Body "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";

// send email 
$success mail($EmailTo$Subject$Body$Name$Address$Telephone "From: <$EmailFrom>");
 
if(
$success) {
header("Location: http://www.example.com/thankyou.htm");
exit();
} else {
header("Location: http://www.example.com/error.htm");
exit(); 
I would suggest that you use PHP sessions on all the pages concerning the email form as it's much easier to transfer data between pages .
I get this error message:

Parse error: parse error in /home/www/robrag.hostingrapid.com/contact2.php on line 28

http://robrag.hostingrapid.com/contact2.php
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-04-2006, 10:16 PM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
I think I'm not getting the $EmailTo variable. Because it's not in the contact form so how can the PHP get it?

<form method="POST" action="contact2.php">
Fields marked (*) are required

<p>Email From:* <br>
<input type="text" name="EmailFrom">
<p>Subject:* <br>
<input type="text" name="Subject">
<p>Name:* <br>
<input type="text" name="Name">
<p>Address:* <br>
<input type="text" name="Address">
<p>Telephone:* <br>
<input type="text" name="Telephone">
<p><input type="submit" name="submit" value="Submit">
</form>
<p>
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-05-2006, 08:57 AM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
OK guys and gals. I'm getting closer. ** Taps self on back **

The error page dislpays perfectly.

But, if you fill out all the fields you're not taken to the thank you page, this is what appears:


Warning: mail() expects at most 5 parameters, 7 given in /home/www/robrag.hostingrapid.com/contact2.php on line 29

Warning: Cannot modify header information - headers already sent by (output started at /home/www/robrag.hostingrapid.com/contact2.php:29) in /home/www/robrag.hostingrapid.com/contact2.php on line 35


Here's the link to try it yourself:

http://robrag.hostingrapid.com/contactus.htm

And, here's the PHP program/code:

PHP Code:
<?php
$EmailTo 
"christine@lawnsbythebest.com";
// Captures the form variables, saves you writing out each and every variable :)
foreach($_POST as $key => $val) {
$
$key trim(stripslashes($val));
}
/* Validates the form data. Because every field is required, you can use another loop to save time coding */
foreach($_POST as $key => $val) {
$empty "";
if(
$val == $empty) {
header("Location: http://robrag.hostingrapid.com/error.htm");
exit();
}
}
 
// prepare email body text
$Body "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";

// send email 
$success mail($EmailTo$Subject$Body$Name$Address$Telephone"From: <$EmailFrom>");
 
if(
$success) {
header("Location: http://robrag.hostingrapid.com/thankyou.htm");
exit();
} else {
header("Location: http://robrag.hostingrapid.com/error.htm");
exit();} 
?>
Thanks!!!!
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-05-2006, 10:59 PM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
And by the way here's the HTML:

HTML Code:
<form method="POST" action="contact2.php">
Fields marked (*) are required

<p>Email From:* <br>
<input type="text" name="EmailFrom">
<p>Subject:* <br>
<input type="text" name="Subject">
<p>Name:* <br>
<input type="text" name="Name">
<p>Address:* <br>
<input type="text" name="Address">
<p>Telephone:* <br>
<input type="text" name="Telephone">
<p><input type="submit" name="submit" value="Submit">
</form>
<p>
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-06-2006, 02:30 AM
Skilled Talker

Posts: 70
Trades: 0
i just tried the page then and i got to the thankyou page

and i checked the code and the problem is in the mail function. When i gave you the code i put that variable in <> tags, indicating that whatever the your email address variable should go there. I guess you used the variable $EmailFrom. I apologise for any inconvenience on my part. Removing the tags would've fixed the problem straightaway .

Last edited by cerebro89; 01-06-2006 at 02:35 AM..
cerebro89 is offline
Reply With Quote
View Public Profile
 
Old 01-06-2006, 08:01 AM
Robert_R's Avatar
Skilled Talker

Posts: 97
Location: New Jersey
Trades: 0
Quote:
Originally Posted by cerebro89
i just tried the page then and i got to the thankyou page

and i checked the code and the problem is in the mail function. When i gave you the code i put that variable in <> tags, indicating that whatever the your email address variable should go there. I guess you used the variable $EmailFrom. I apologise for any inconvenience on my part. Removing the tags would've fixed the problem straightaway .
OK, my friend I think we're almost there! LOL!

I've checked and the filled in form is not sent to the email address I specified.

PHP code:

PHP Code:
<?php
$EmailTo 
'christine@lawnsbythebest.com';
// Captures the form variables, saves you writing out each and every variable :)
foreach($_POST as $key => $val) {
$
$key trim(stripslashes($val));
}
/* Validates the form data. Because every field is required, you can use another loop to save time coding */
foreach($_POST as $key => $val) {
$empty "";
if(
$val == $empty) {
header("Location: http://robrag.hostingrapid.com/error.htm");
exit();
}
}
 
// prepare email body text
$Body "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";

// send email 
$success mail($EmailTo$Subject$Body$Name"From: <$EmailFrom>");
 
if(
$success) {
header("Location: http://robrag.hostingrapid.com/thankyou.htm");
exit();
} else {
header("Location: http://robrag.hostingrapid.com/error.htm");
exit();} 
?>
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 01-08-2006, 10:56 AM
Skilled Talker

Posts: 70
Trades: 0
try changing the code to this:

Code:
<?php 
$EmailTo = 'christine@lawnsbythebest.com';
// Captures the form variables, saves you writing out each and every variable :) 
foreach($_POST as $key => $val) { 
$$key = trim(stripslashes($val)); 
} 
/* Validates the form data. Because every field is required, you can use another loop to save time coding */ 
foreach($_POST as $key => $val) { 
$empty = ""; 
if($val == $empty) { 
header("Location: http://robrag.hostingrapid.com/error.htm"); 
exit(); 
} 
} 
 
// prepare email body text and additional headers
$Headers = "From: $EmailFrom";
$Body = ""; 
$Body .= "Name: "; 
$Body .= $Name; 
$Body .= "\n"; 
$Body .= "Address: "; 
$Body .= $Address; 
$Body .= "\n"; 
$Body .= "Telephone: "; 
$Body .= $Telephone; 
$Body .= "\n"; 
 
// send email 
if(mail($EmailTo, $Subject, $Body,$Headers)) { 
header("Location: http://robrag.hostingrapid.com/thankyou.htm"); 
exit(); 
} else { 
header("Location: http://robrag.hostingrapid.com/error.htm"); 
exit();} 
?>
See if that works BTW the name of the person is in the email, and thus isn't required as part of the from header

Last edited by cerebro89; 01-08-2006 at 10:59 AM..
cerebro89 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP contact form. Need additional fields.
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.74115 seconds with 12 queries