portsmouthinkstore Posted May 16, 2009 Share Posted May 16, 2009 I build a few sites for friends and family and just started using PHP for html form submission. I want the html form created in dreamweaver to be completed by the user and when SUBMIT is clicked, an email is sent to me (or whoever) with the form details. I have tried a few examples on other sites. When I copy their html code form example, and their corresponding php script, it works fine. I get an email with all the info required. If I ammend the code to work with my form eg changing the basic form text field request to the text field names of my form boxes, it doesn't work? I get an email but no info from any boxes? I have noticed that there seems to be a difference in manually typing html form code to create a text box compared with the auto dreamweaver add text box methods. The html code is slightly different. So I manually created the same form without using dreamweaver's click and add method (just typed the code and created the text fields) but again the same result. No info in the email. I need someone to start me off is anybody is that helpful. I have copied below the html code for a basic form I created in dreamweaver (this time I just used dreamweaver rather than manually typing code as this is how I will normally work, lazy I guess). Can someone help with the PHP code I would need to get this form emailed to me? Most my forms have more fields than the exaple shown below but I figure if I can see how the lines of PHP code work, I can ammend to suite each form. UNLESS, I guess there is a chance that every form needs bespoke PHP. As I said, I'm new. I recently opened an account with Webfusion as 123 reg didn't support PHP. Any help or advice would be greatly appreciated. HTML Form code: (nothing on this test page but the form) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Feedback</title> </head> <body><form action="" method="post" name="Feedback"> <table width="700" border="0" align="center" cellpadding="0" cellspacing="3"> <tr> <td width="144">Full Name:</td> <td width="547"><label for="Full Name"></label> <input type="text" name="Full Name" id="Full Name" /></td> </tr> <tr> <td>Email Address:</td> <td><label for="Email Address"></label> <input type="text" name="Email Address" id="Email Address" /></td> </tr> <tr> <td>Gender:</td> <td>Male <input type="checkbox" name="Gender Male" id="Gender Male" /> <label for="Gender Male"> Female <input type="checkbox" name="Gender Female" id="Gender Female" /> </label></td> </tr> <tr> <td>How you heard of us:</td> <td>Google <input type="checkbox" name="How you heard of us Google" id="How you heard of us Google" /> <label for="How you heard of us Google"> Reccomendation <input type="checkbox" name="How you heard of us reccomended" id="How you heard of us reccomended" /> </label></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Comments:</td> <td><label for="Comments"></label> <textarea name="Comments" id="Comments" cols="45" rows="5"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><label for="Submit"></label> <input type="submit" name="Submit" id="Submit" value="Submit Form" /></td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/ Share on other sites More sharing options...
doa24uk Posted May 16, 2009 Share Posted May 16, 2009 We'll need the php code too......... Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835241 Share on other sites More sharing options...
wildteen88 Posted May 16, 2009 Share Posted May 16, 2009 One problem I see is your field names contains spaces and are far too complicated. You should not have spaces within your field names and you should keep your field names simple, for example name="email" is much simpler than name="Email Address" Also for gender you should use radio buttons rather than checkboxes. For the gender I'd do: <td>Gender:</td> <td> Male <input type="checkbox" name="gender" value="male" /> Female <input type="checkbox" name="gender" value="female" /> </td> In PHP you'd use $_POST['gender'] to retrieve what the user selected. But yeah we'll need to see you PHP code in order to help you. Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835249 Share on other sites More sharing options...
portsmouthinkstore Posted May 16, 2009 Author Share Posted May 16, 2009 OK sorry, If I copy and paste this form into dreamweaver - <form method="post" action="sendmail.php"> Email: <input name="email" type="text" /><br /> Message:<br /> <textarea name="message" rows="15" cols="40"> </textarea><br /> <input type="submit" /> </form> (copied from someones HELP) and then use their PHP scrip - <?php $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; mail( "[email protected]", "Feedback Form Results", $message, "From: $email" ); header( "Location: http://www.example.com/thankyou.html" ); ?> everything works as it should (I have to change the email addy to send to) When I modify that PHP script for my form - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Feedback</title> </head> <body><form action="sendmail.php" method="post" name="Feedback"> <table width="700" border="0" align="center" cellpadding="0" cellspacing="3"> <tr> <td width="144">Full Name:</td> <td width="547"><label for="Full Name"></label> <input type="text" name="Full Name" id="Full Name" /></td> </tr> <tr> <td>Email Address:</td> <td><label for="Email Address"></label> <input type="text" name="Email Address" id="Email Address" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Comments:</td> <td><label for="Comments"></label> <textarea name="Comments" id="Comments" cols="45" rows="5"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><label for="Submit"></label> <input type="submit" name="Submit" id="Submit" value="Submit Form" /></td> </tr> </table> </form> </body> </html> My modified PHP reads - <?php $FullName = $_REQUEST['Full Name'] ; $Email = $_REQUEST['Email Address'] ; $comments = $_REQUEST['comments'] ; mail( "*****", "Feedback Form Results", $Full Name, $comments, $Email Address ); header( "Location: http://www.dkdebtmanagement.html" ) ?> I did get a few errors (where $FullName had a space in between but when I remove the space the error goes. Now it just shows the address sendmail.php and a cannot be displayed page? I'm probably way off but HELP! Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835252 Share on other sites More sharing options...
portsmouthinkstore Posted May 16, 2009 Author Share Posted May 16, 2009 thanks for the tip on the field names, will ammend. Advice immediately, I like it. Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835255 Share on other sites More sharing options...
portsmouthinkstore Posted May 16, 2009 Author Share Posted May 16, 2009 anyone see obvious errors with that script? Seems straight forward but not? The form is submitted but no firld data is sent???? An I thought HTML was bad enough. Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835302 Share on other sites More sharing options...
portsmouthinkstore Posted May 16, 2009 Author Share Posted May 16, 2009 Right then, my html dreamweaver form now reads: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Feedback</title> </head> <body><form action="sendmail.php" method="post" name="Feedback"> <table width="700" border="0" align="center" cellpadding="0" cellspacing="3"> <tr> <td width="144">Full Name:</td> <td width="547"><label for="name"></label> <input type="text" name="name" id="name" /></td> </tr> <tr> <td>Email Address:</td> <td><label for="email"></label> <input type="text" name="email" id="email" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Comments:</td> <td><label for="comments"></label> <textarea name="comments" id="comments" cols="45" rows="5"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><label for="Submit"></label> <input type="submit" name="Submit" id="Submit" value="Submit Form" /></td> </tr> </table> </form> </body> </html> and my PHP script reads: <?php $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; $comments = $_REQUEST['comments'] ; mail( "****", "Feedback Form Results", $name, $email, $comments); header( "Location: http://www.dkdebtmanagement.co.uk" ) ?> Seems simple enough but all I get is data entered into the name field, no Name = *** just **** and anything entered into the comments box is displayed with the email header Feedback Form Results (then data in comments box). Seems so confusing for such a small ammount of code, it appears straight forward but.... Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835303 Share on other sites More sharing options...
wildteen88 Posted May 16, 2009 Share Posted May 16, 2009 The use of the mail function is not quite right here mail( "****", "Feedback Form Results", $name, $email, $comments); Only $name will be seen in the email. $email/$comments will be sent as additional headers which is not what you want. What you should do is: <?php $name = $_POST['name'] ; $email = $_POST['email'] ; $comments = $_POST['comments'] ; $message = "Name: $name\nEmail: $email\nComments: $comments"; mail( "****", "Feedback Form Results", $message); header( "Location: http://www.dkdebtmanagement.co.uk" ) ?> All I did was assign the body of the email to the $message variable. I then passed this to the mail function. Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835310 Share on other sites More sharing options...
farvahar Posted May 16, 2009 Share Posted May 16, 2009 why not using phpmailer? it is much better than mail() function. Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835317 Share on other sites More sharing options...
portsmouthinkstore Posted May 17, 2009 Author Share Posted May 17, 2009 cheers wildteen, worked. I need to get the mail from to read whatever they enetered in the email text field. I'v seen the code somewhere but cant remember. To validate text fields, should I just use dreamweavers validate methods or is it better to do this with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/158380-first-time-using-php-help/#findComment-835791 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.