Results 1 to 6 of 6

Thread: dynamic subject in email form

  1. #1
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default dynamic subject in email form

    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?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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):

    Code:
    <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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    here is what i have so far:
    Code:
    <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>

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I modified that code and it worked perfectly. thanks !

  6. #6
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:
    Code:
    <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.
    Last edited by Pitchy; 01-03-2008 at 03:28 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •