<form> Problems!

  • PieMan
  • Born
  • Born
  • PieMan
  • Posts: 3

Post 3+ Months Ago

Hi all,

I am trying to setup a “contact us” page on my site and have come upon a problem I can’t fix.

I want 5 destination email addresses picked by radio buttons. In the main it is working OK, but no matter which destination you pick the email always goes through to the last one webmaster@mydomain.com.

The emails I receive when I test the form have the correct info, Enquiries if I pick enquiries or Sales if I pick sales, but always come through to the webmaster address.

I expect it is something quite simple because if I change the last email on the list to enquiries@mydomain.com all the mails come through to that address. Could someone have a look at my code and set me straight.

Code: [ Select ]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
function get_radio_value()
{
for (var i=0; i < 5; i++)
  {
  if (document.email.mail[i].checked)
   {
   var rad_val = document.email.e-mail[i].value;
   }
  }
}

//-->
</SCRIPT>
</head>

<body>
<table align="center" width="99%" border="1" cellpadding="5" cellspacing="1"> <form name="email" method="POST" action="../cgi-bin/formmail/formmail.cgi">
<td width="742" height="28">Speak to us about an existing order.</td>
<td width="150"><input type="radio" name="mail" value="Orders">
<inputtype="hidden"name="recipient"value=orders@mydomain.com>
&&&<b>Orders</b></td>
</tr>
<tr>
<td height="28">Talk to us about a past order.</td>
<td><input type="radio" name="mail" value="Sales">
<input type="hidden" name="recipient" value="sales@mydomain.com">
&&&<b>Sales</b></td>
</tr>
<tr>
<td height="28">Mail us about anything related to mydomain.com</td>
<td><input type="radio" name="mail" value="Enquiries">
<input type="hidden" name="recipient" value="enquiries@mydomain.com">
&&&<b>Enquiries</b></td>
</tr>
<tr>
<td height="28">Talk to our current featured artist.</td>
<td><input type="radio" name="mail" value="Joe">
<input type="hidden" name="recipient" value="joe@mydomain.com">
&&&<b>Joe</b></td>
</tr>
<tr>
<td height="28">Inform us about any problems on this site.</td>
<td><input type="radio" name="mail" value="WebMaster">
<input type="hidden" name="recipient" value="webmaster@mydomain.com">
&&&<b>WebMaster</b></td><br><br>
</tr>
<tr>
<td height="184" colspan="2" align="center" valign="top">
<table border='0' cellspacing='1' cellpadding='1' width='250'>
<tr>
<td width="100%" align="center"><br><font color="#FF0000">*</font>
Your Name:<input type="text" name="realname" size="30"><br><br>
<font color="#FF0000">*</font>Your Email:<input type="text" name="email" size="30"><br><br>
Subject:<input type="text" name="subject" size="81"><br>
Your Comments:<br><textarea name="comments" cols="70" rows="7"></textarea></td>
</tr>
</table><font size="1" color="#FF0000">*required</font>
</td>
</tr>
</table><br><center>
<input type="submit" name="Send" value="  Send  " onClick="get_radio_value()"></center>
<input type="hidden" name="posted" value="1">
<input type="hidden" name="required" value="realname,email,comments">
<input type="hidden" name="redirect" value="http://www.mydomain.com/contact_us_submission.php">
</form><br><br>
</td>
</tr>
</table>
</body>
</html>
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <script language="JavaScript" type="text/javascript">
  6. <!--
  7. function get_radio_value()
  8. {
  9. for (var i=0; i < 5; i++)
  10.   {
  11.   if (document.email.mail[i].checked)
  12.    {
  13.    var rad_val = document.email.e-mail[i].value;
  14.    }
  15.   }
  16. }
  17. //-->
  18. </SCRIPT>
  19. </head>
  20. <body>
  21. <table align="center" width="99%" border="1" cellpadding="5" cellspacing="1"> <form name="email" method="POST" action="../cgi-bin/formmail/formmail.cgi">
  22. <td width="742" height="28">Speak to us about an existing order.</td>
  23. <td width="150"><input type="radio" name="mail" value="Orders">
  24. <inputtype="hidden"name="recipient"value=orders@mydomain.com>
  25. &&&<b>Orders</b></td>
  26. </tr>
  27. <tr>
  28. <td height="28">Talk to us about a past order.</td>
  29. <td><input type="radio" name="mail" value="Sales">
  30. <input type="hidden" name="recipient" value="sales@mydomain.com">
  31. &&&<b>Sales</b></td>
  32. </tr>
  33. <tr>
  34. <td height="28">Mail us about anything related to mydomain.com</td>
  35. <td><input type="radio" name="mail" value="Enquiries">
  36. <input type="hidden" name="recipient" value="enquiries@mydomain.com">
  37. &&&<b>Enquiries</b></td>
  38. </tr>
  39. <tr>
  40. <td height="28">Talk to our current featured artist.</td>
  41. <td><input type="radio" name="mail" value="Joe">
  42. <input type="hidden" name="recipient" value="joe@mydomain.com">
  43. &&&<b>Joe</b></td>
  44. </tr>
  45. <tr>
  46. <td height="28">Inform us about any problems on this site.</td>
  47. <td><input type="radio" name="mail" value="WebMaster">
  48. <input type="hidden" name="recipient" value="webmaster@mydomain.com">
  49. &&&<b>WebMaster</b></td><br><br>
  50. </tr>
  51. <tr>
  52. <td height="184" colspan="2" align="center" valign="top">
  53. <table border='0' cellspacing='1' cellpadding='1' width='250'>
  54. <tr>
  55. <td width="100%" align="center"><br><font color="#FF0000">*</font>
  56. Your Name:<input type="text" name="realname" size="30"><br><br>
  57. <font color="#FF0000">*</font>Your Email:<input type="text" name="email" size="30"><br><br>
  58. Subject:<input type="text" name="subject" size="81"><br>
  59. Your Comments:<br><textarea name="comments" cols="70" rows="7"></textarea></td>
  60. </tr>
  61. </table><font size="1" color="#FF0000">*required</font>
  62. </td>
  63. </tr>
  64. </table><br><center>
  65. <input type="submit" name="Send" value="  Send  " onClick="get_radio_value()"></center>
  66. <input type="hidden" name="posted" value="1">
  67. <input type="hidden" name="required" value="realname,email,comments">
  68. <input type="hidden" name="redirect" value="http://www.mydomain.com/contact_us_submission.php">
  69. </form><br><br>
  70. </td>
  71. </tr>
  72. </table>
  73. </body>
  74. </html>


Thanks for your help,

Regards

PieMan

---------------------------------------------------------------
Edited by ATNO to fix the code display.
PieMan, please use the BBcode or the Code buttons when ever you post any kind of code. Otherwise it won't display properly.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

I'm not certain how to write the exact code for it, but I can suggest what I think you need to do.

I think you need to lose all those hidden inputs for recipient, then in your script test for the value of "mail", then write an if statement so that if "mail" equals sales then "mail" equals sales@mydomain.com else if "mail" equals joe the "mail" equals joe@mydomain.com and so on. Then make the recipient variable equal to the "mail" variable.

I think that would do what you want.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

I think ATNO is right, and the multiple hidden fields with the same value are causing a problem. When I tested the form on my own server by just echoing the input I found the only one of these fields that was sent was the last one that was in the form. In other words, only one field with the same name can go through and the last one declared with the name seems to be the one.

Rather than use hidden fields perhaps you could just put the values into the radio buttons themselves and then the only one that will go through is the one that the user selects since you can have multiple radio buttons with the same name (a radio group) and only the selected one goes through.

The only possible problem with this would be if they fail to select a radio button the there will be no recipient, so you might want to add some client-side javascript to validate the form. Then the problem would be if they don't have javascript enabled and don't select a radio button. I would think that your formmail script would require that field and generate some kind of error message, although I'm not sure exactly what it would be.

Anyway, here is what it would look like without the validation code:

Code: [ Select ]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table align="center" width="99%" border="1" cellpadding="5" cellspacing="1">
<form name="email" method="post" action="../cgi-bin/formmail/formmail.cgi">
<td width="742" height="28">Speak to us about an existing order.</td>
<td width="150"><input type="radio" name="recipient" value="orders@mydomain.com">
&&&<b>Orders</b></td>
</tr>
<tr>
<td height="28">Talk to us about a past order.</td>
<td><input type="radio" name="recipient" value="sales@mydomain.com">
&&&<b>Sales</b></td>
</tr>
<tr>
<td height="28">Mail us about anything related to mydomain.com</td>
<td><input type="radio" name="recipient" value="enquiries@mydomain.com">
&&&<b>Enquiries</b></td>
</tr>
<tr>
<td height="28">Talk to our current featured artist.</td>
<td><input type="radio" name="recipient" value="joe@mydomain.com">
&&&<b>Joe</b></td>
</tr>
<tr>
<td height="28">Inform us about any problems on this site.</td>
<td><input type="radio" name="recipient" value="webmaster@mydomain.com">
&&&<b>WebMaster</b></td><br><br>
</tr>
<tr>
<td height="184" colspan="2" align="center" valign="top">
<table border='0' cellspacing='1' cellpadding='1' width='250'>
<tr>
<td width="100%" align="center"><br><font color="#FF0000">*</font>
Your Name:<input type="text" name="realname" size="30"><br><br>
<font color="#FF0000">*</font>Your Email:<input type="text" name="email" size="30"><br><br>
Subject:<input type="text" name="subject" size="81"><br>
Your Comments:<br><textarea name="comments" cols="70" rows="7"></textarea></td>
</tr>
</table><font size="1" color="#FF0000">*required</font>
</td>
</tr>
</table><br><center>
<input type="submit" name="Send" value="  Send  "></center>
<input type="hidden" name="posted" value="1">
<input type="hidden" name="required" value="realname,email,comments">
<input type="hidden" name="redirect" value="http://www.mydomain.com/contact_us_submission.php">
</form><br><br>
</td>
</tr>
</table>
</body>
</html>
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. </head>
  6. <body>
  7. <table align="center" width="99%" border="1" cellpadding="5" cellspacing="1">
  8. <form name="email" method="post" action="../cgi-bin/formmail/formmail.cgi">
  9. <td width="742" height="28">Speak to us about an existing order.</td>
  10. <td width="150"><input type="radio" name="recipient" value="orders@mydomain.com">
  11. &&&<b>Orders</b></td>
  12. </tr>
  13. <tr>
  14. <td height="28">Talk to us about a past order.</td>
  15. <td><input type="radio" name="recipient" value="sales@mydomain.com">
  16. &&&<b>Sales</b></td>
  17. </tr>
  18. <tr>
  19. <td height="28">Mail us about anything related to mydomain.com</td>
  20. <td><input type="radio" name="recipient" value="enquiries@mydomain.com">
  21. &&&<b>Enquiries</b></td>
  22. </tr>
  23. <tr>
  24. <td height="28">Talk to our current featured artist.</td>
  25. <td><input type="radio" name="recipient" value="joe@mydomain.com">
  26. &&&<b>Joe</b></td>
  27. </tr>
  28. <tr>
  29. <td height="28">Inform us about any problems on this site.</td>
  30. <td><input type="radio" name="recipient" value="webmaster@mydomain.com">
  31. &&&<b>WebMaster</b></td><br><br>
  32. </tr>
  33. <tr>
  34. <td height="184" colspan="2" align="center" valign="top">
  35. <table border='0' cellspacing='1' cellpadding='1' width='250'>
  36. <tr>
  37. <td width="100%" align="center"><br><font color="#FF0000">*</font>
  38. Your Name:<input type="text" name="realname" size="30"><br><br>
  39. <font color="#FF0000">*</font>Your Email:<input type="text" name="email" size="30"><br><br>
  40. Subject:<input type="text" name="subject" size="81"><br>
  41. Your Comments:<br><textarea name="comments" cols="70" rows="7"></textarea></td>
  42. </tr>
  43. </table><font size="1" color="#FF0000">*required</font>
  44. </td>
  45. </tr>
  46. </table><br><center>
  47. <input type="submit" name="Send" value="  Send  "></center>
  48. <input type="hidden" name="posted" value="1">
  49. <input type="hidden" name="required" value="realname,email,comments">
  50. <input type="hidden" name="redirect" value="http://www.mydomain.com/contact_us_submission.php">
  51. </form><br><br>
  52. </td>
  53. </tr>
  54. </table>
  55. </body>
  56. </html>


and with a very simple validation code that just checks to make sure that a radio button is selected and there is something in the other two required fields. This doesn't test for a valid email, but there are plenty of functions like that available freely on the web and you could just substitute the code for one for the current function.

Code: [ Select ]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
function validate() {
    if(checkRecipient() && checkName() && checkEmail()) return true;
    return false;
}
function checkRecipient() {
    for (var i=0; i < document.email.recipient.length; i++)
    {
        if (document.email.recipient[i].checked) return true;
    }
    alert("Please select a department.");
    return false;
}
function checkEmail() {
    if(document.email.email.value != "") return true;
    alert("Please enter your email address");
    return false;
}
function checkName() {
    if(document.email.realname.value != "") return true;
    alert("Please enter your name");
    return false;
}
//-->
</SCRIPT>
</head>

<body>
<table align="center" width="99%" border="1" cellpadding="5" cellspacing="1">
<form name="email" method="post" action="../cgi-bin/formmail/formmail.cgi" onsubmit=" return validate()">
<td width="742" height="28">Speak to us about an existing order.</td>
<td width="150"><input type="radio" name="recipient" value="orders@mydomain.com">
&&&<b>Orders</b></td>
</tr>
<tr>
<td height="28">Talk to us about a past order.</td>
<td><input type="radio" name="recipient" value="sales@mydomain.com">
&&&<b>Sales</b></td>
</tr>
<tr>
<td height="28">Mail us about anything related to mydomain.com</td>
<td><input type="radio" name="recipient" value="enquiries@mydomain.com">
&&&<b>Enquiries</b></td>
</tr>
<tr>
<td height="28">Talk to our current featured artist.</td>
<td><input type="radio" name="recipient" value="joe@mydomain.com">
&&&<b>Joe</b></td>
</tr>
<tr>
<td height="28">Inform us about any problems on this site.</td>
<td><input type="radio" name="recipient" value="webmaster@mydomain.com">
&&&<b>WebMaster</b></td><br><br>
</tr>
<tr>
<td height="184" colspan="2" align="center" valign="top">
<table border='0' cellspacing='1' cellpadding='1' width='250'>
<tr>
<td width="100%" align="center"><br><font color="#FF0000">*</font>
Your Name:<input type="text" name="realname" size="30"><br><br>
<font color="#FF0000">*</font>Your Email:<input type="text" name="email" size="30"><br><br>
Subject:<input type="text" name="subject" size="81"><br>
Your Comments:<br><textarea name="comments" cols="70" rows="7"></textarea></td>
</tr>
</table><font size="1" color="#FF0000">*required</font>
</td>
</tr>
</table><br><center>
<input type="submit" name="Send" value="  Send  "></center>
<input type="hidden" name="posted" value="1">
<input type="hidden" name="required" value="realname,email,comments">
<input type="hidden" name="redirect" value="http://www.mydomain.com/contact_us_submission.php">
</form><br><br>
</td>
</tr>
</table>
</body>
</html>
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <script language="JavaScript" type="text/javascript">
  6. <!--
  7. function validate() {
  8.     if(checkRecipient() && checkName() && checkEmail()) return true;
  9.     return false;
  10. }
  11. function checkRecipient() {
  12.     for (var i=0; i < document.email.recipient.length; i++)
  13.     {
  14.         if (document.email.recipient[i].checked) return true;
  15.     }
  16.     alert("Please select a department.");
  17.     return false;
  18. }
  19. function checkEmail() {
  20.     if(document.email.email.value != "") return true;
  21.     alert("Please enter your email address");
  22.     return false;
  23. }
  24. function checkName() {
  25.     if(document.email.realname.value != "") return true;
  26.     alert("Please enter your name");
  27.     return false;
  28. }
  29. //-->
  30. </SCRIPT>
  31. </head>
  32. <body>
  33. <table align="center" width="99%" border="1" cellpadding="5" cellspacing="1">
  34. <form name="email" method="post" action="../cgi-bin/formmail/formmail.cgi" onsubmit=" return validate()">
  35. <td width="742" height="28">Speak to us about an existing order.</td>
  36. <td width="150"><input type="radio" name="recipient" value="orders@mydomain.com">
  37. &&&<b>Orders</b></td>
  38. </tr>
  39. <tr>
  40. <td height="28">Talk to us about a past order.</td>
  41. <td><input type="radio" name="recipient" value="sales@mydomain.com">
  42. &&&<b>Sales</b></td>
  43. </tr>
  44. <tr>
  45. <td height="28">Mail us about anything related to mydomain.com</td>
  46. <td><input type="radio" name="recipient" value="enquiries@mydomain.com">
  47. &&&<b>Enquiries</b></td>
  48. </tr>
  49. <tr>
  50. <td height="28">Talk to our current featured artist.</td>
  51. <td><input type="radio" name="recipient" value="joe@mydomain.com">
  52. &&&<b>Joe</b></td>
  53. </tr>
  54. <tr>
  55. <td height="28">Inform us about any problems on this site.</td>
  56. <td><input type="radio" name="recipient" value="webmaster@mydomain.com">
  57. &&&<b>WebMaster</b></td><br><br>
  58. </tr>
  59. <tr>
  60. <td height="184" colspan="2" align="center" valign="top">
  61. <table border='0' cellspacing='1' cellpadding='1' width='250'>
  62. <tr>
  63. <td width="100%" align="center"><br><font color="#FF0000">*</font>
  64. Your Name:<input type="text" name="realname" size="30"><br><br>
  65. <font color="#FF0000">*</font>Your Email:<input type="text" name="email" size="30"><br><br>
  66. Subject:<input type="text" name="subject" size="81"><br>
  67. Your Comments:<br><textarea name="comments" cols="70" rows="7"></textarea></td>
  68. </tr>
  69. </table><font size="1" color="#FF0000">*required</font>
  70. </td>
  71. </tr>
  72. </table><br><center>
  73. <input type="submit" name="Send" value="  Send  "></center>
  74. <input type="hidden" name="posted" value="1">
  75. <input type="hidden" name="required" value="realname,email,comments">
  76. <input type="hidden" name="redirect" value="http://www.mydomain.com/contact_us_submission.php">
  77. </form><br><br>
  78. </td>
  79. </tr>
  80. </table>
  81. </body>
  82. </html>


// edit
I forgot to change the method back to post and the action address back to your path, but I just edited it.
  • PieMan
  • Born
  • Born
  • PieMan
  • Posts: 3

Post 3+ Months Ago

Thanks, I'll give it a try and let you know.

Regards

PieMan

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 49 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.