View Full Version : dynamic subject in email form
aRabidLunatic
05-09-2007, 01:43 AM
I have a form where users input certain information into text boxes. basically a Contact Me form. Right now its just a HTML Form. Is there a way to have the information from one of the text boxes appear at the end of the subject in the email. Lets say a text has: "John Smith". I want the subject to read: "Contact Form - John Smith". I'm pretty sure this will require some javascript or a more advanced language. Any suggestions?
thetestingsite
05-09-2007, 02:21 AM
How is your form set up (the source code for the form that is)? Probably the best way would be to have a server side language (PHP, ASP, etc) process the form and send the email like that. In the script, you could simply append the text from one field into the subject. For a javascript alternative (if you have your email address in the action attribute of the form) would be something like this (not the best way, but still works):
<html>
<head>
<script type="text/javascript">
function addActionTest(theForm) {
if (theForm.testField.value != '') {
theForm.action += theForm.testField.value;
return true;
}
else { alert('Error'); return false;}
}
</script>
</head>
<body>
<form name="testForm" action="mailto:me@domain.com?subject=Contact Form - " method="POST" onsubmit="return addActionTest(this);">
<input type="text" name="testField">
<input type="submit">
</form>
</body>
</html>
(for a demo of the above, go to http://phphost.smackum.com/dd/test.html)
Hope this helps.
aRabidLunatic
05-09-2007, 05:20 PM
here is what i have so far:
<html>
<head><title>Escalation Form</title></head>
<body bgcolor="#FFFFCC">
<form action="myEmailAddy@nowhere.com?subject=ESCALATION REQUEST" method="post" enctype="text/plain">
<table>
<tr>
<td>
<h2>ESCALATION REQUEST</H2>
CSR:<INPUT NAME="CSR " TYPE="text" SIZE=20 MAXLENGTH=20><BR />
<br />
Date:<INPUT NAME="Date " TYPE="text" SIZE=15 MAXLENGTH=15><BR />
Account #:<INPUT NAME="Account# " TYPE="text" SIZE=15 MAXLENGTH=15><BR />
Sub Name:<INPUT NAME="Customer Name " TYPE="text" SIZE=20 MAXLENGTH=20><BR />
Contact Name: <INPUT NAME="-Contact Name " TYPE="text" SIZE=10 MAXLENGTH=15><BR />
Contact TN:<INPUT NAME="-Contact TN " TYPE="text" SIZE=10 MAXLENGTH=15><BR />
Time of Call:<INPUT NAME="Time of Call " TYPE="text" SIZE=10 MAXLENGTH=10><BR /><br />
Customer Concern/Details:<br /><TEXTAREA NAME="Customer Concerns " ROWS=5 COLS=45></TEXTAREA><BR>
</td></tr>
<tr><td align=center>
<INPUT TYPE="submit" value="Send Email" style="color: #ffffff; background-color: blue">
</td>
</tr>
</table>
</FORM>
<body>
</html>
thetestingsite
05-09-2007, 05:29 PM
Then you can modify the code I posted in my previous post to suit your needs. Simply change the form field names (in the javascript), then that should do it.
Hope this helps.
aRabidLunatic
05-09-2007, 05:32 PM
I modified that code and it worked perfectly. thanks !
Pitchy
01-03-2008, 02:48 PM
Google has landed me here because I am trying to do a similar thing. I am curious if it is possible to do the same thing, but use the Add function listed above to work with a drop down / list box and add the value from the list to the subject line?
I think where I am having a problem is my form action is using a cgi script, so I am not sure how to modify this to work. Downside to hosting with GoDaddy I guess... since I can only use one email address for form mail and that's selected inside their control panel.
I was hoping this would work:
<input type="hidden" name="subject" value="Contest Submission: " onsubmit="return addActionTest(this);" />
but I haven't got it to work yet.
Thanks in advance for any help you can provide.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.