Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Need Help With Form!, help?
Sten
post Jul 7 2007, 03:39 AM
Post #1


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



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

This post has been edited by Sten: Jul 7 2007, 05:18 AM
Go to the top of the page
 
+Quote Post
lonelym
post Jul 7 2007, 11:33 AM
Post #2


Member - Active Contributor
Group Icon

Group: Members
Posts: 91
Joined: 18-May 07
Member No.: 22,008



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
Go to the top of the page
 
+Quote Post
Sten
post Jul 7 2007, 11:42 AM
Post #3


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



umm... well thanks but it was only meant to be a contact form. just emailing to me.
Go to the top of the page
 
+Quote Post
pyost
post Jul 7 2007, 02:18 PM
Post #4


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



QUOTE(Sten @ Jul 7 2007, 05:39 AM) *
and i also just realised that i forgot to add the </form> to the end. lol. would that be y it isnt working?


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

HTML
<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

HTML
<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.
Go to the top of the page
 
+Quote Post
Sten
post Jul 8 2007, 02:24 AM
Post #5


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



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?
Go to the top of the page
 
+Quote Post
Habble
post Jul 8 2007, 03:24 AM
Post #6


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
From: Tasmania
Member No.: 22,699



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
Go to the top of the page
 
+Quote Post
Sten
post Jul 8 2007, 03:32 AM
Post #7


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



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 biggrin.gif

This post has been edited by Sten: Jul 8 2007, 04:38 AM
Go to the top of the page
 
+Quote Post
pyost
post Jul 8 2007, 03:54 PM
Post #8


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



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

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.
Go to the top of the page
 
+Quote Post
jlhaslip
post Jul 22 2007, 05:05 AM
Post #9


Advanced Member
Group Icon

Group: Members
Posts: 187
Joined: 15-November 05
From: Inland from the Left Coast of Canada
Member No.: 9,627



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.

This post has been edited by jlhaslip: Jul 22 2007, 05:07 AM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Design A Contact Form Part 3(0)
  2. Code To Send An Email From A Form(10)
  3. How To Design A Form In Flex 2(0)
  4. How To Make Simple Animations In The Gimp(2)
  5. Design A Contact Form In Flex Part 1(0)
  6. PHP Tutorial: Form Verification And Simple Validation(12)
  7. Request Form Site Suspended(4)
  8. Problem With Form Elements(3)
  9. Nice Form(9)
  10. Web Form Generator(5)
  11. Question About An Email Form(4)
  12. Submiting Form Data To "file.php?action=login"(7)
  13. Quickly Create Form Variables(5)
  14. Updating An Rss File Using A Php Form(1)
  15. Bug With Firefox(4)
  1. Storing Data Into Xml With A Php Form(2)
  2. What's Wrong With This Form?(5)
  3. Form Prompt(1)
  4. Advanced Form Question(0)
  5. Virtuemart Question(0)
  6. A Big Hug Form Down Under(0)
  7. Need Help With Javascript Form Validation(2)
  8. Contact Form(3)
  9. Contact Form Script Trouble(10)
  10. How To Move A Database Form Astahost To Trap17(5)
  11. Creat A Cool Image In Photshop(3)
  12. Getting Form Information To Database Query(7)
  13. Windows Firewall Blocks An Item Form Msn(1)
  14. Making A Simple Webpage Generator: Part 2(0)
  15. "button-pushing" Website(2)


 



- Lo-Fi Version Time is now: 10th October 2008 - 07:49 PM