• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

How do I add a submit_to email to this form?

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>
0
lengel1
Asked:
lengel1
  • 6
  • 2
1 Solution
 
Michel PlungjanIT ExpertCommented:
<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>
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
lengel1Author 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;
  }
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Michel PlungjanIT ExpertCommented:
I can have a look tomorrow.
0
 
Michel PlungjanIT ExpertCommented:
You did NOT post the actual form

What is the idea of the form? To send a specific article via email, no?

Instead you are trying to change the action to a specific article...

What does enableState do?

I think you want something more like

articles = new Array(
"http://cms.ieee.org/portal/innovate/freearticle/download1_1540-7993.html",
"http://cms.ieee.org/portal/innovate/freearticle/download2_0740-7459.html",
"http://cms.ieee.org/portal/innovate/freearticle/download3_0018-9200.html",
"http://cms.ieee.org/portal/innovate/freearticle/download4_0163-6804.html",
"http://cms.ieee.org/portal/innovate/freearticle/download5_0018-9200.html",
"http://cms.ieee.org/portal/innovate/freearticle/download6_0890-8044.html"
); // note the lack of comma on the last item

function chkArticle(theRad) {
  theRad.form.elements['Select_Article'].value = articles[theRad.value];
}

where you have

<input name="aArticle" value="0" onClick="chkArticle(this)" type="radio">Article 1
<input name="aArticle" value="1" onClick="chkArticle(this)" type="radio">Article 2
0
 
lengel1Author 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.

0
 
Michel PlungjanIT ExpertCommented:
Please post or send me the complete form and whether or not you want to display or email the article.
0
 
Michel PlungjanIT ExpertCommented:
Helloo?
0
 
timhighamCommented:
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now