We help IT Professionals succeed at work.

How do I add a submit_to email to this form?

lengel1
lengel1 asked
on
349 Views
Last Modified: 2013-12-25
I've been trying to use the below as a basis for developing a more complicated form, but this is the general idea. I will have multiple radio buttons, and depending on which button you choose, you will be directed to a specific html page.

I am using a cgi form script in my version of the file and though I have the correct "thank you" page, as it were, showing up, the cgi script isn't sending the data and email to me.

Can some one help me understand what the conflict is by using this simple version below? So, how would you automatically send this information to an email address on submit?

<SCRIPT language="JavaScript">
function OnSubmitForm()
{
  if(document.myform.operation[0].checked == true)
  {
    document.myform.action ="http://www.ieee.org";
  }
  else
  if(document.myform.operation[1].checked == true)
  {
    document.myform.action ="http://www.amazon.com";
  }
  return true;
}
</SCRIPT>

  <FORM name="myform" onSubmit="return OnSubmitForm();">
    Name: <INPUT TYPE="TEXT" Name="name"><br>
    Email: <INPUT TYPE="TEXT" Name="email"><br>
    <input type="radio" name="operation" value="1" checked>Insert
    <input type="radio" name="operation" value="2">Update
    <P>
    <INPUT TYPE="SUBMIT" name="Submit" VALUE="Save">
    </P>
 </FORM>
Comment
Watch Question

Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
<SCRIPT language="JavaScript">
function OnSubmitForm(theForm) {
  if(theForm.operation[0].checked) {
    theForm.action ="mailto:mail1@mail.com";
  }
  else if(theForm.operation[1].checked) {
    theForm.action ="mailto:mail2@mail.com";
  }
  return true;
}
</SCRIPT>

  <FORM name="myform" onSubmit="return OnSubmitForm(this);">
    Name: <INPUT TYPE="TEXT" Name="name"><br>
    Email: <INPUT TYPE="TEXT" Name="email"><br>
    <input type="radio" name="operation" value="1" checked>Mail1
    <input type="radio" name="operation" value="2">Mail2
    <P>
    <INPUT TYPE="SUBMIT" name="Submit" VALUE="Save">
    </P>
 </FORM>
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
However since you posted this in the CGI area, why do any javascript and mailto at all
Look at the radio on the server and send the mail FROM the server - much more likely to succeed and you will not show your mail addresses to everyone

Author

Commented:
//HERE'S is the actual form

<form action="http://www.ieee.org/cgi-bin/bnbform.cgi" method="post" name="myform" onSubmit="if (checkFields()) return true; else return false;">
<input name="submit_to" type="hidden" value="l.engel@ieee.org, lisaengel1@mac.com"/>
<input name="required" type="hidden" value="First_Name, Last_Name, submit_by, Industry, Business_Type, Country, Select_Article"/>
<input name="data_order" type="hidden" value="First_Name, Last_Name, submit_by, Phone, Industry, Business_Type, Country, State_Province, Select_Article"/>
<input name="form_id" type="hidden" value="Free IEEE Article"/>
<input name="ok_url" type="hidden" value="http://cms.ieee.org/portal/innovate/freearticle/thankyou.html"/>

// HERE'S a sample of one of the six buttons
<input name="aArticle" value="1" onClick="chkArticle('1')" type="radio">

//HERE'S the external JavaScript validation.. it IS delivering the correct page depending on what radio is selected, but the cgi form action is not sending me the email with the data I want to be collecting from the user... is there a conflict in the form.action that is preventing the cgi from being executed?

function enablestate()
{
      var selObj = document.getElementById("State_Province");

      if ((document.myform.elements['Country'].value == 'United States') || (document.myform.elements['Country'].value == 'Canada'))
      {
            selObj.options[66] = null;
            document.myform.elements['State_Province'].disabled = false;
      }else {
            selObj.options[66]=new Option("Outside the U.S or Canada" , "Outside the U.S or Canada");
            selObj.options[66].selected = true;
            document.myform.elements['State_Province'].disabled = true;
            
            
      }
}

function chkArticle(x)
{
      document.myform.elements['Select_Article'].value = x;
}

function checkFields(myform)
{
if(document.myform.aArticle[0].checked == true)
{
document.myform.action ="http://cms.ieee.org/portal/innovate/freearticle/download1_1540-7993.html";
}
if(document.myform.aArticle[1].checked == true)
{
document.myform.action ="http://cms.ieee.org/portal/innovate/freearticle/download2_0740-7459.html";
}
if(document.myform.aArticle[2].checked == true)
{
document.myform.action ="http://cms.ieee.org/portal/innovate/freearticle/download3_0018-9200.html";
}
if(document.myform.aArticle[3].checked == true)
{
document.myform.action ="http://cms.ieee.org/portal/innovate/freearticle/download4_0163-6804.html";
}
if(document.myform.aArticle[4].checked == true)
{
document.myform.action ="http://cms.ieee.org/portal/innovate/freearticle/download5_0018-9200.html";
}
if(document.myform.aArticle[5].checked == true)
{
document.myform.action ="http://cms.ieee.org/portal/innovate/freearticle/download6_0890-8044.html";
}
missinginfo = "";
if (document.myform.elements['First_Name'].value == "")
{
missinginfo += "\n     -  First Name";
}
if (document.myform.elements['Last_Name'].value == "")
{
missinginfo += "\n     -  Last Name";
}
if (document.myform.elements['submit_by'].value == "")
{
missinginfo += "\n     -  E-mail";
}
if (document.myform.elements['Country'].value == "")
{
missinginfo += "\n     -  Country";
}
if ((document.myform.elements['Country'].value == 'United States' || document.myform.elements['Country'].value == 'Canada') && document.myform.elements['State_Province'].value == "")
{
missinginfo += "\n     -  State/Province";
}
if (document.myform.elements['Select_Article'].value == "")
{
missinginfo += "\n     -  Choose an Article";
}
 
if (missinginfo != "")
  {
    missinginfo ="_____________________________\n" +
                       "The following information is missing:\n" +
                       missinginfo + "\n_____________________________" +
                       "\nPlease re-enter and submit again!";
    alert(missinginfo);
    return false;
  }
   else {
      var email = document.myform.elements['submit_by'].value;
      if (email.indexOf("@") == -1){
      
          missinginfo += "\n     -  Email";
          missinginfo ="_____________________________\n" +
                             "The following information is not valid:\n" +
                             missinginfo + "\n_____________________________" +
                             "\nPlease re-enter and submit again!";
          alert(missinginfo);
          return false;         
         }
   
        return true;
  }
}
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
I can have a look tomorrow.
IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
The idea behind the form is to have a choice of six articles to download, depending on which radio button is selected.

Depending on which radio button is clicked a specific page (indicated by the ok_url) would be displayed.

The enableState is to activate a state/province field if US or Canada is chosen.

I tried plunking in your code (thank you!), but it doesn't deliver the unique page, just the original ok_url thank you in the form, and the e-mail isn't coming through.

Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Please post or send me the complete form and whether or not you want to display or email the article.
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Helloo?
With all respect you seem to be complicating things. You have a webpage form to collect data.
That data can be from anyone and you can be subject to corrupt data or malicious attacks from this approach.
Consider having serverside data protection such as PHP first, allowing the server to email on valid data, or place it in a database for on demand viewing and storage or both (recommend PEAR addon for PHP).
If you are not familiar with this it is easy to learn, or has ASP equivalents.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.