Mailto: subject line populated by form data

Status
Not open for further replies.

Hookster264

In Runtime
Messages
162
Location
Denver, CO
I am creating a simple Form to collect data from a user and submit to an email. It will include just three fields; State, Account and a textarea section for free text message.

I know you can pre-populate the subject to whatever free text you choose, like:
?subject=My custom subject line">

But can you code the subject line to pre-populate to include data entered in the form by the user? I want the subject line to include the State Code-Account number and followed by my own free text. Thanks
 
if you're using a server side language such as PHP or ASP.NET, this is a piece of cake.

These languages have built in functions for writing form data in the HTML page.

If you want to do it with a standalone HTML page, it gets tricky. However, I still think it's possible. I'm having a tough time figuring out how to use Javascript to access the form data though. Ah ha, found it.

JavaScript Form Validation

you'll need to write a javascript function to dynamically create a mailto link
 
Customizing a subject line when submitting a form via email is quite easy. This is all I did.

My form had fields for State and Account.
In my js matilto: ?subject="+frm.state.value+" - "+frm.acount.value+" Authorized User&

Subject line looked like this: CA-East19 Authorized User

This populated the subject line with whatever the user entered into the form plus my own text afterwards.
 
i'm glad to hear you were able to complete the task. Just for clarification, I'm guessing the name of the form was frm and this form includes at least two inputs named state and account. These would need to be changed if anyone else was trying to re-create the solution.

What method was used by the form? get or post?
 
Customizing a subject line when submitting a form via email is quite easy. This is all I did.

My form had fields for State and Account.
In my js matilto: ?subject="+frm.state.value+" - "+frm.acount.value+" Authorized User&

Subject line looked like this: CA-East19 Authorized User

This populated the subject line with whatever the user entered into the form plus my own text afterwards.
Hookster, I can't get this to work in my document. Can you be more specific about where to place this line? Does it go in my form tag? I get a subject line that says WWW Form Submission. (Also, it looks like you misspelled mailto in your script.) Thanks,

DD
 
you could add the line to an onclick event for a html object, like a button.

Code:
<form name=myform>
<input type=text name=myname>
<input type=text name=myaddress>
<input type=button value="Click Me" onclick="window.location='mailto:me@domain.com?subject='+myform.myname.value+' - '+myform.myaddress.value">
</form>

try that out.
 
you could add the line to an onclick event for a html object, like a button.

Code:
<form name=myform>
<input type=text name=myname>
<input type=text name=myaddress>
<input type=button value="Click Me" onclick="window.location='mailto:me@domain.com?subject='+myform.myname.value+' - '+myform.myaddress.value">
</form>

try that out.

Or onSubmit

Code:
<form name="myform" onSubmit="window.location='mailto:me@domain.com?subject='+myform.myname.value+' - '+myform.myaddress.value">
<input type="text" name="myname">
<input type="text" name="myaddress">
<input type="submit" name="submit" value="submit">
</form>
 
No luck. Probalby because I'm using an external script for validation. Can you tell me how to make it work with this script?

<script type="text/JavaScript" src="http://www.siue.edu/commencement/commencement_web_site.js" language="JavaScript"><!----></script>
<form onsubmit="return checkFieldsCommencement()" name="commencementform" action="http://www.siue.edu/cgi-bin/FormMail.pl" method="post">
<input name="recipient" type="hidden" value="ddennis@siue.edu" />
<input name="email" type="hidden" value="ddennis@siue.edu" />
<input name="subject" type="hidden" value="Commencement Form" />
<input name="redirect" type="hidden" value="http://www.siue.edu/commencement/acknowledgement.shtml" />

What I want to do is have the value of commencementform.name appear in the subject line after the words Commencement Form . Seems like I could do it with the subject input field, if I could get the right syntax.

Thanks for your advice.
 
Code:
<script type="text/JavaScript" src="http://www.siue.edu/commencement/commencement_web_site.js" language="JavaScript"><!----></script>
<form onsubmit="return checkFieldsCommencement();window.location='mailto:me@domain.com?subject='+commencementform.name.value" name="commencementform" action="http://www.siue.edu/cgi-bin/FormMail.pl" method="post">
<input name="recipient" type="hidden" value="ddennis@siue.edu" />
<input name="email" type="hidden" value="ddennis@siue.edu" />
<input name="subject" type="hidden" value="Commencement Form" />
<input name="redirect" type="hidden" value="http://www.siue.edu/commencement/acknowledgement.shtml" />

Try this.
 
Status
Not open for further replies.
Back
Top Bottom