bookmark - Need Help With Form! help?

Need Help With Form! - help?

 
 Discussion by Sten with 8 Replies.
 Last Update: July 22, 2007, 5:05 am
 
bookmark - Need Help With Form! help?  
    
free web hosting
 
Well, for my site i need a contact form and a few other forms. ive written all the html.
I need the php for it though, im not great at php and some help would be nice! no tutorials or anything seem to work so im gathering im doing it wrong.

Whoever wants to help, if u would like to, could you also explain?

Here ist the form so u no wot to use:

CODE

<form action="contact_send.php" method="post">
<table width="510" border="0">
<tr>
<td width="50">
<font size="2" face="verdana"><b>Habbo Name:
</td>
<td><input size="25" name="Name">
</td>
</tr>
<td>

<font size="2" face="verdana"><b>Email Address:
</td>
<td>
<input size="25" name="Email">
</td>
</tr>
<td>
<font size="2" face="verdana"><b>Reason:
</td>
<td><select name="Reason"><option>Feedback</option><option>Complaint</option><option>Idea</option><option>Rare Value Suggestion</option><option>Help Me</option><option>Other</option></select>
</td>
</tr>
<tr>
<td>
<font size="2" face="verdana"><b>Your Message:
</td>
<td><textarea name="Message" rows="6" cols="40"></textarea>
</td>
</tr>
<tr>
<td><input type="submit" name="Send" value="Send Message">
</td>
</tr>
</table>


and i also just realised that i forgot to add the </form> to the end. lol. would that be y it isnt working? the cpanel isnt working at the moment to change it!

anyway, thanks in advance for any help!

i wonder if i shouldve put this in the programming section somewhere... lol

Sat Jul 7, 2007    Reply    New Discussion   


These are the form names that you used: Name, Email, Message, Reason

Guessing that this is a registration code that you are working on, you make a new php file, and write the following.

Make sure you are connected to the database, and you have supplied the username, password, and the correct host information.

CODE

<?PHP
//Fill this up. Make sure that the table has only 4 fields, which is the username, user email, message, and reason.
$tablename = "";

$user_name = $_GET[Name];
$user_email = $_GET[Email];
$user_message = $_GET[Message];
$user_reason = $_GET[Reason];

$QUERY = "INSERT INTO $tablename VALUES ($user_name, $user_email, $user_message, $user_reason)";
$RESULT = mysql_query($QUERY);
if ($RESULT){
print "The information was added to the database";
}else {
print "There was an error. Maybe you weren't connected to the database?";
}
?>


If your table which the values will be inserted to has more fields, please tell me so I can edit this post or make a new post to help you out.

Good luck

Sat Jul 7, 2007    Reply    New Discussion   

umm... well thanks but it was only meant to be a contact form. just emailing to me.

Sat Jul 7, 2007    Reply    New Discussion   

QUOTE (Sten)

and i also just realised that i forgot to add the </form> to the end. lol. would that be y it isnt working?
Link: view Post: 106951


No matter whether it works or not (and it might depending on the browser being used), it is always good practice to close each and every one of the tags. It is a W3C standard, after all.

What you should change, however, is the drop-down box code. Instead of

CODE

<select name="Reason"><option>Feedback</option><option>Complaint</option><option>Idea</option><option>Rare Value Suggestion</option><option>Help Me</option><option>Other</option></select>


use

CODE

<select name="Reason"><option value="Feedback">Feedback</option><option value="Complaint">Complaint</option><option value="Idea">Idea</option><option value="Rare Value Suggestion">Rare Value Suggestion</option><option value="Help Me">Help Me</option><option value="Other">Other</option></select>


This way you define values to be sent to the PHP file.

As for the PHP code, with slight alterations to the one Sten provided, it should mail you properly.

CODE

<?php
$to = 'someone@example.com';
$subject = 'Contact e-mail';

$user_name = $_GET['Name'];
$user_email = $_GET['Email'];
$user_message = $_GET['Message'];
$user_reason = $_GET['Reason'];

$message = "Name: $user_name \n E-mail: $user_email \n\n $user_message \n\n Reason: $user_reason";

if !( mail( $to, $subject, $message ) ) {
echo 'Mail not sent!';
}

?>


The first two variable should be edited to contain you e-mail address and the message subject you want to use. The next four rows insert all the sent data into four variables, which are then joined to for the mail body. I hope that the only thing you might find confusing is "\n" - it defines a new line in the message body. With that in mind, you would receive an e-mail like this:

QUOTE

Name: John Smith
E-mail: johnsmith@gmail.com

John Smith's message.

Reason: Feedback


The last several lines send the e-mail, and failure to do so results in a "Mail not sent" message.

Be sure to inform me of any problems you encounter.

Sat Jul 7, 2007    Reply    New Discussion   


Well... it sends to me. I had to change $_GET to $_REQUEST to get it to actually display the stuff in the email.

but, no matter if it send or not, it still ses that the mail wasnt sent.

wot do i change to the script to make it just go to a thankyou page once it sends?

Sun Jul 8, 2007    Reply    New Discussion   

change this:

CODE

<?php
$to = 'someone@example.com';
$subject = 'Contact e-mail';

$user_name = $_GET['Name'];
$user_email = $_GET['Email'];
$user_message = $_GET['Message'];
$user_reason = $_GET['Reason'];

$message = "Name: $user_name \n E-mail: $user_email \n\n $user_message \n\n Reason: $user_reason";

if !( mail( $to, $subject, $message ) ) {
echo 'Mail not sent!';
}

?>

to this:

CODE

<?php
$to = 'someone@example.com';
$subject = 'Contact e-mail';

$user_name = $_GET['Name'];
$user_email = $_GET['Email'];
$user_message = $_GET['Message'];
$user_reason = $_GET['Reason'];

$message = "Name: $user_name \n E-mail: $user_email \n\n $user_message \n\n Reason: $user_reason";

if !( mail( $to, $subject, $message ) ) {
echo 'Mail not sent!';
}
else {
echo '<script language="JavaScript" type="Text/JavaScript">document.location = 'thankyou.php';</script>';
}

?>

Replace thankyou.php with the filename of your thank you page

Sun Jul 8, 2007    Reply    New Discussion   

ty jay!

ill try it now, i hope it works!

after about 3 emails jay (habble) got it working for me so yeah... dont bother with this topic anymore <_<

Sun Jul 8, 2007    Reply    New Discussion   

Yeah, this definitely wouldn't work with $_GET, as the data is sent through POST. I overlooked this, my bad <_<

Also, instead of echoing a piece of JavaScript code for redirecting to the ThankYou page, you can also use the PHP header function.

CODE

if !( mail( $to, $subject, $message ) ) {
echo 'Mail not sent!';
}
else {
header('Location: http://www.yoursite.com/thankyou.php');
}


Bare in mind that this will not work if you have already printed out something on the page.

Sun Jul 8, 2007    Reply    New Discussion   

CODE

<?php
$to = 'someone@example.com';
$subject = 'Contact e-mail';

$user_name = $_GET['Name'];
$user_email = $_GET['Email'];
$user_message = $_GET['Message'];
$user_reason = $_GET['Reason'];

$message = "Name: $user_name \n E-mail: $user_email \n\n $user_message \n\n Reason: $user_reason";

$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n";


if !( mail( $to, $subject, $message, $headers) ) {
echo 'Mail not sent!';
}
else {
echo '&lt;script language="JavaScript" type="Text/JavaScript">document.location = 'thankyou.php';</script>';
}

?>

Some Mail Servers require a From header in the mail() even though the php function lists it as an Optional part of the Function's parameters, so review the code above and notice that it uses the variable named $header to add the From and Reply-to headers for the mail script. I have seen mail fail because these headers are missing on the attempt to mail out stuff.

Also, this code does not show any error handling, so another problem might be that the client is leaving one of the required fields blank? Check the Mail function information at the php site: http://www.php.net.

Sun Jul 22, 2007    Reply    New Discussion   

Quickly Post to Need Help With Form! help? w/o signup Share Info about Need Help With Form! help? using Facebook, Twitter etc. email your friend about Need Help With Form! help? Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

A Website what all do i need?  A Website what all do i need? (8) (0) Problem With Selecting A Textbox Content   Problem With Selecting A Textbox Content