Form Send Methods - What is Safest, Best, Easy?

  • GrafinLupus
  • Newbie
  • Newbie
  • User avatar
  • Posts: 9

Post 3+ Months Ago

Please be kind, I'm a newbie struggling to get a survey form on a web site that I just got uploaded to my new host.
I have an HTML form designed with a few text fields, some radio buttons, drop downs, and checkboxes. I built it in Dreamweaver CS5. I was considering using what I now read to be an insecure and not entirely fully supported by all browsers (or cell phones or tablets) mailto method:

Code: [ Select ]
<form name="form1" method="post" action="mailto:myname at mysite .com" enctype="text/plain"> yada yada form contents etc.</form>


Now I read on many sites that it may be better to use PHP, JavaScript or some other files to do this better and have more features. Features like restricting input on some fields to numbers or types of characters (like an email address with at symbol) or preventing bots from gleaning sensitive data or I don't know what all. HELP please.

Here's some code that I got from one form generator site for an example html file. This I pretty much understand:

Code: [ Select ]
<style>
.robotext {font-weight: bold; font-size: 9pt; color: #999999; font-family: Arial, Helvetica, sans-serif; text-decoration: none}
.robolink:link {font-weight: bold; font-size: 9pt; color: #999999; font-family: Arial, Helvetica, sans-serif; text-decoration: none}
.robolink:hover {font-weight: bold; font-size: 9pt; color: #979653; font-family: Arial, Helvetica, sans-serif; text-decoration: underline}
.robolink:visited {font-weight: bold; font-size: 9pt; color: #979653; font-family: Arial, Helvetica, sans-serif; text-decoration: none}
</style>
<script language="Javascript">
function validate(){
var allok = true;
 if(htmlphpformgenerator1.What_is_your_household_income_per_year__2.selectedIndex == 0 ){
  alert('Invalid input for What is your household income per year');
  return false;
 }
 if(isNaN(htmlphpformgenerator1.How_much_did_you_spend_for_food_rounded_to_the_nearest_dollar__7.value)){
  alert('Invalid input for How much did you spend for food (rounded to the nearest dollar, this must be a number')
  return false;
 }
document.htmlphpformgenerator1.Submit.disabled="disabled";
return true;
}
</script>
<form name="htmlphpformgenerator1" method="Post" action="htmlphpformgenerator1.php" onSubmit="return validate();">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr><td>Name</td><td><input type="edit" name="Name__1" value="" size="20"></td></tr>
<tr><td>What is your household income per year?</td><td><select name="What_is_your_household_income_per_year__2"><option value="less than $40,000" selected>less than $40,000</option>
<option value="40,000 to $59,999">40,000 to $59,999</option>
<option value="$60,000 to $79,999">$60,000 to $79,999</option>
<option value="$80,000 to $99,999">$80,000 to $99,999</option>
<option value="greater than $100,000">greater than $100,000</option>
<option value=""></option>
</select></td></tr>
<tr><td>How many adults live at home?</td><td><input type="edit" name="How_many_adults_live_at_home__3" value="" size="2"></td></tr>
<tr><td></td><td><input type="edit" name="__4" value="" size="20"></td></tr>
<tr><td valign=top>Have your ever eaten at a theme restaurant?</td><td valign=top>
 <input type="radio" name="Have_your_ever_eaten_at_a_theme_restaurant__4" value="Yes" checked>Yes<br>
<input type="radio" name="Have_your_ever_eaten_at_a_theme_restaurant__4" value="No">No<br>
</td></tr>
<tr><td>Name a restaurant that you would typically go to without the kids.</td><td><input type="edit" name="Name_a_restaurant_that_you_would_typically_go_to_without_the_kids__5" value="" size="50"></td></tr>
<tr><td valign=top>What kind of work did you perform at the event?</td><td valign=top><input type="checkbox" name="Food_preparation__6" value="Yes">Food preparation<br>
<input type="checkbox" name="Food_sales_or_Serving__6" value="Yes">Food sales or Serving<br>
<input type="checkbox" name="Maintenance__6" value="Yes">Maintenance<br>
<input type="checkbox" name="Logistics__6" value="Yes">Logistics<br>
<input type="checkbox" name="Entertainer__6" value="Yes">Entertainer<br>
<input type="checkbox" name="Demonstration__6" value="Yes">Demonstration<br>
<input type="checkbox" name="Souvenir_craft_art_or_product_Sales__6" value="Yes">Souvenir, craft, art or product Sales<br>
<input type="checkbox" name="Parking_or_Traffic_Control__6" value="Yes">Parking or Traffic Control<br>
<input type="checkbox" name="Security__6" value="Yes">Security<br>
<input type="checkbox" name="Other__6" value="Yes">Other</td></tr>
<tr><td>How much did you spend for food (rounded to the nearest dollar?</td><td><input type="edit" name="How_much_did_you_spend_for_food_rounded_to_the_nearest_dollar__7" value="" size="5"></td></tr>
<tr><td colspan=2><input type="submit" name="Submit" value="Submit Survey"></td></tr>
<tr><td colspan=2 class=robotext><a href="http://www.phpform .info" class="robolink">HTML/PHP Form Generator</a> from ROBO Design Solutions</td></tr></table></form>
  1. <style>
  2. .robotext {font-weight: bold; font-size: 9pt; color: #999999; font-family: Arial, Helvetica, sans-serif; text-decoration: none}
  3. .robolink:link {font-weight: bold; font-size: 9pt; color: #999999; font-family: Arial, Helvetica, sans-serif; text-decoration: none}
  4. .robolink:hover {font-weight: bold; font-size: 9pt; color: #979653; font-family: Arial, Helvetica, sans-serif; text-decoration: underline}
  5. .robolink:visited {font-weight: bold; font-size: 9pt; color: #979653; font-family: Arial, Helvetica, sans-serif; text-decoration: none}
  6. </style>
  7. <script language="Javascript">
  8. function validate(){
  9. var allok = true;
  10.  if(htmlphpformgenerator1.What_is_your_household_income_per_year__2.selectedIndex == 0 ){
  11.   alert('Invalid input for What is your household income per year');
  12.   return false;
  13.  }
  14.  if(isNaN(htmlphpformgenerator1.How_much_did_you_spend_for_food_rounded_to_the_nearest_dollar__7.value)){
  15.   alert('Invalid input for How much did you spend for food (rounded to the nearest dollar, this must be a number')
  16.   return false;
  17.  }
  18. document.htmlphpformgenerator1.Submit.disabled="disabled";
  19. return true;
  20. }
  21. </script>
  22. <form name="htmlphpformgenerator1" method="Post" action="htmlphpformgenerator1.php" onSubmit="return validate();">
  23. <table width="100%" border="0" cellpadding="5" cellspacing="0">
  24. <tr><td>Name</td><td><input type="edit" name="Name__1" value="" size="20"></td></tr>
  25. <tr><td>What is your household income per year?</td><td><select name="What_is_your_household_income_per_year__2"><option value="less than $40,000" selected>less than $40,000</option>
  26. <option value="40,000 to $59,999">40,000 to $59,999</option>
  27. <option value="$60,000 to $79,999">$60,000 to $79,999</option>
  28. <option value="$80,000 to $99,999">$80,000 to $99,999</option>
  29. <option value="greater than $100,000">greater than $100,000</option>
  30. <option value=""></option>
  31. </select></td></tr>
  32. <tr><td>How many adults live at home?</td><td><input type="edit" name="How_many_adults_live_at_home__3" value="" size="2"></td></tr>
  33. <tr><td></td><td><input type="edit" name="__4" value="" size="20"></td></tr>
  34. <tr><td valign=top>Have your ever eaten at a theme restaurant?</td><td valign=top>
  35.  <input type="radio" name="Have_your_ever_eaten_at_a_theme_restaurant__4" value="Yes" checked>Yes<br>
  36. <input type="radio" name="Have_your_ever_eaten_at_a_theme_restaurant__4" value="No">No<br>
  37. </td></tr>
  38. <tr><td>Name a restaurant that you would typically go to without the kids.</td><td><input type="edit" name="Name_a_restaurant_that_you_would_typically_go_to_without_the_kids__5" value="" size="50"></td></tr>
  39. <tr><td valign=top>What kind of work did you perform at the event?</td><td valign=top><input type="checkbox" name="Food_preparation__6" value="Yes">Food preparation<br>
  40. <input type="checkbox" name="Food_sales_or_Serving__6" value="Yes">Food sales or Serving<br>
  41. <input type="checkbox" name="Maintenance__6" value="Yes">Maintenance<br>
  42. <input type="checkbox" name="Logistics__6" value="Yes">Logistics<br>
  43. <input type="checkbox" name="Entertainer__6" value="Yes">Entertainer<br>
  44. <input type="checkbox" name="Demonstration__6" value="Yes">Demonstration<br>
  45. <input type="checkbox" name="Souvenir_craft_art_or_product_Sales__6" value="Yes">Souvenir, craft, art or product Sales<br>
  46. <input type="checkbox" name="Parking_or_Traffic_Control__6" value="Yes">Parking or Traffic Control<br>
  47. <input type="checkbox" name="Security__6" value="Yes">Security<br>
  48. <input type="checkbox" name="Other__6" value="Yes">Other</td></tr>
  49. <tr><td>How much did you spend for food (rounded to the nearest dollar?</td><td><input type="edit" name="How_much_did_you_spend_for_food_rounded_to_the_nearest_dollar__7" value="" size="5"></td></tr>
  50. <tr><td colspan=2><input type="submit" name="Submit" value="Submit Survey"></td></tr>
  51. <tr><td colspan=2 class=robotext><a href="http://www.phpform .info" class="robolink">HTML/PHP Form Generator</a> from ROBO Design Solutions</td></tr></table></form>


Here's the accompanying PHP code they gave me to paste into a .php file. This is where I am lost. If I want to tweak the fields in the survey, without studying PHP for a couple months, I have no idea what to do to make the .php files compatible. I don't even know where to put the PHP code (between tags? which tags?:

Code: [ Select ]
<?php
$email = "myemail at yahoo .com";
$message = "The following information was submitted from the form on your website:\n
";
$message .= "Name: ".$_REQUEST["Name__1"]."\n\n";
$message .= "What is your household income per year : ".$_REQUEST["What_is_your_household_income_per_year__2"]."\n\n";
$message .= "How many adults live at home : ".$_REQUEST["How_many_adults_live_at_home__3"]."\n\n";
$message .= "Have your ever eaten at a theme restaurant : ".$_REQUEST["Have_your_ever_eaten_at_a_theme_restaurant__4"]."\n\n";
$message .= "Name a restaurant that you would typically go to without the kids.: ".$_REQUEST["Name_a_restaurant_that_you_would_typically_go_to_without_the_kids__5"]."\n\n";
$message .= "What kind of work did you perform at the event?: ".$_REQUEST[What_kind_of_work_did_you_perform_at_the_event__6]."\n\n";
$message .= "Food preparation: ".$_REQUEST[Food_preparation__6]."\n\n";
$message .= "Food sales or Serving: ".$_REQUEST[Food_sales_or_Serving__6]."\n\n";
$message .= "Maintenance: ".$_REQUEST[Maintenance__6]."\n\n";
$message .= "Logistics: ".$_REQUEST[Logistics__6]."\n\n";
$message .= "Entertainer: ".$_REQUEST[Entertainer__6]."\n\n";
$message .= "Demonstration: ".$_REQUEST[Demonstration__6]."\n\n";
$message .= "Souvenir, craft, art or product Sales: ".$_REQUEST[Souvenir_craft_art_or_product_Sales__6]."\n\n";
$message .= "Parking or Traffic Control: ".$_REQUEST[Parking_or_Traffic_Control__6]."\n\n";
$message .= "Security: ".$_REQUEST[Security__6]."\n\n";
$message .= "Other: ".$_REQUEST[Other__6]."\n\n";
$message .= "How much did you spend for food (rounded to the nearest dollar : ".$_REQUEST["How_much_did_you_spend_for_food_rounded_to_the_nearest_dollar__7"]."\n\n";
mail( $email, "Form Submission from your http://www. domain. com website", $message, "From: $email X-Priority: 1 (Highest)" );
header("Location: http://www. domain .com/page. php");
?>
  1. <?php
  2. $email = "myemail at yahoo .com";
  3. $message = "The following information was submitted from the form on your website:\n
  4. ";
  5. $message .= "Name: ".$_REQUEST["Name__1"]."\n\n";
  6. $message .= "What is your household income per year : ".$_REQUEST["What_is_your_household_income_per_year__2"]."\n\n";
  7. $message .= "How many adults live at home : ".$_REQUEST["How_many_adults_live_at_home__3"]."\n\n";
  8. $message .= "Have your ever eaten at a theme restaurant : ".$_REQUEST["Have_your_ever_eaten_at_a_theme_restaurant__4"]."\n\n";
  9. $message .= "Name a restaurant that you would typically go to without the kids.: ".$_REQUEST["Name_a_restaurant_that_you_would_typically_go_to_without_the_kids__5"]."\n\n";
  10. $message .= "What kind of work did you perform at the event?: ".$_REQUEST[What_kind_of_work_did_you_perform_at_the_event__6]."\n\n";
  11. $message .= "Food preparation: ".$_REQUEST[Food_preparation__6]."\n\n";
  12. $message .= "Food sales or Serving: ".$_REQUEST[Food_sales_or_Serving__6]."\n\n";
  13. $message .= "Maintenance: ".$_REQUEST[Maintenance__6]."\n\n";
  14. $message .= "Logistics: ".$_REQUEST[Logistics__6]."\n\n";
  15. $message .= "Entertainer: ".$_REQUEST[Entertainer__6]."\n\n";
  16. $message .= "Demonstration: ".$_REQUEST[Demonstration__6]."\n\n";
  17. $message .= "Souvenir, craft, art or product Sales: ".$_REQUEST[Souvenir_craft_art_or_product_Sales__6]."\n\n";
  18. $message .= "Parking or Traffic Control: ".$_REQUEST[Parking_or_Traffic_Control__6]."\n\n";
  19. $message .= "Security: ".$_REQUEST[Security__6]."\n\n";
  20. $message .= "Other: ".$_REQUEST[Other__6]."\n\n";
  21. $message .= "How much did you spend for food (rounded to the nearest dollar : ".$_REQUEST["How_much_did_you_spend_for_food_rounded_to_the_nearest_dollar__7"]."\n\n";
  22. mail( $email, "Form Submission from your http://www. domain. com website", $message, "From: $email X-Priority: 1 (Highest)" );
  23. header("Location: http://www. domain .com/page. php");
  24. ?>


There has to be an easier way to do this without paying some company loads of money and losing control of my design and data. Data which, BTW, I have no idea how I will gather and decipher. With the mailto method I could at least sort it out with an excel query.
Sorry I'm so long winded.
Advice on this would be greatly appreciated.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 473

Post 3+ Months Ago

OK if your server is a server that can run php some things you need to know about the php script you have are you want to make sure your syntax is correct.

incorrect = $_REQUEST[Food_preparation__6]

correct = $_REQUEST['Food_preparation__6'] OR $_REQUEST["Food_preparation__6"]

To make things a bit easier for you you can do
something like

HTML Code: [ Select ]
<form method="Post" action="myphp.php">
<input type="text" name="my_name" value="Notice the name" />
<input type="text" name="my_city" value="some city" />
<input type="submit" value="Go!" />
</form>
 
  1. <form method="Post" action="myphp.php">
  2. <input type="text" name="my_name" value="Notice the name" />
  3. <input type="text" name="my_city" value="some city" />
  4. <input type="submit" value="Go!" />
  5. </form>
  6.  


myphp.php
PHP Code: [ Select ]
<?php
 
// by using this it will make it easier for you not to mess up the syntax. Every form element in your form that had a name attribute will become the exact text inside the "" for example the my_name input will be able to be used in php as $my_name IF you call extract other wise it will be able to be use by one of these $_POST['my_name']; $_POST["my_name"]; $_REQUEST['my_name']; $_REQUEST["my_name"];  
extract($_POST);
 
$email = "myemail at yahoo .com";
 
message = "The following information was submitted from the form on your website:\n
";
 
$message .= "Name: $my_name\n\n";
$message .= "City: $my_city\n\n";
 
mail($email, "Form Submission from your http://www. domain. com website", $message);
 
?>
 
  1. <?php
  2.  
  3. // by using this it will make it easier for you not to mess up the syntax. Every form element in your form that had a name attribute will become the exact text inside the "" for example the my_name input will be able to be used in php as $my_name IF you call extract other wise it will be able to be use by one of these $_POST['my_name']; $_POST["my_name"]; $_REQUEST['my_name']; $_REQUEST["my_name"];  
  4. extract($_POST);
  5.  
  6. $email = "myemail at yahoo .com";
  7.  
  8. message = "The following information was submitted from the form on your website:\n
  9. ";
  10.  
  11. $message .= "Name: $my_name\n\n";
  12. $message .= "City: $my_city\n\n";
  13.  
  14. mail($email, "Form Submission from your http://www. domain. com website", $message);
  15.  
  16. ?>
  17.  
  • GrafinLupus
  • Newbie
  • Newbie
  • User avatar
  • Posts: 9

Post 3+ Months Ago

Thank you ScottG, but your reply is mostly over my head. Maybe I'm totally out of my league on this forum. Perhaps I need to cave in and hire someone to do this for me. I'm running out of life.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 473

Post 3+ Months Ago

You said you had a form built right? Post that or send me a pm of the details
  • GrafinLupus
  • Newbie
  • Newbie
  • User avatar
  • Posts: 9

Post 3+ Months Ago

ScottG wrote:
You said you had a form built right? Post that or send me a pm of the details


ScottG,
Thank you again! I just figured it all out. I found another much better example of what I wanted to do. Works great! Now I understand what you were trying to show me.
Now I have a problem getting a spry menu bar that uses javascript to display the sub-levels on any smart phone. It works fine on Firefox and IE so I guess I just need to find code to make it work on other devices.
I will look for other info on that in this forum or post a new question.
Wish me luck.
Thanks again.
GrafinLupus
  • Nightslyr
  • Proficient
  • Proficient
  • Nightslyr
  • Posts: 283

Post 3+ Months Ago

Tip: never use the $_REQUEST super global array. It contains everything in GET, POST, and COOKIE. That means if you have something in two or more of those with the same name (which is plausible) you won't know exactly which version you're dealing with. If you have a cookie named 'blah' that contains old information, and a new version of ' blah' that is passed in via POST, which are you sending to the database*?

So, use the right array for the right job. $_GET for GET requests, $_POST for POST requests, etc.

* Yes, there's a PHP.ini setting you can set that will set the $_REQUEST hierarchy, but why risk it? Furthermore, using the proper array makes code infinitely more readable, which is very important if you're doing something non-trivial.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 154 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.