homepage Welcome to WebmasterWorld Guest from 174.129.103.100
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Online form help needed please.
Maledicta




msg:3871591
 7:08 pm on Mar 16, 2009 (gmt 0)

Hi all

I've been asked to set up an online form for a side project at work, and unfortunately, I only have a very small understanding of javascript.

The form needs to send data directly to a specified email address rather than bring up an email box, which is what it's doing at the moment due to the mailto: command. Here's the HTML part of the form (I've had to take out my email address for privacy reasons):

<form name="omaform" action="mailto:email@address.com?subject="From the suggestion box">
Your Name: (optional)<br>
<input type="text" size="26" name="Name"><br><br>
Your Suggestion:<br>
<textarea name="Suggestion" rows="8" cols="20">
</textarea><br><br>
<input type="submit" value="Submit Suggestion">
</form>

Can anyone provide me with the .js code or anything else I'd need to have the data from the form sent directly to the email? It's meant to be for anonymous submissions so obviously having the email edit box pop up isn't any good!

The site this will be on is hosted on a Streamline server if that's any help!

 

blang




msg:3871924
 3:45 am on Mar 17, 2009 (gmt 0)

You don't need any JavaScript to submit an email via the mailto: specifier, but you will need to specify the method (POST) and the encoding type (text/plain), e.g.

<form name="x" method="POST" action="mailto:your_addy@..." enctype="text/plain">
...
</form>

I strongly suggest, however, that you use a server-side script using Perl, PHP, ASP, Java, etc that accepts the form and processes the email for you rather than exposing the address, giving direct access to a form with your email address (or your client's email!) and allowing chaos to ensue.

Maledicta




msg:3871980
 7:54 am on Mar 17, 2009 (gmt 0)

Thanks for the reply Blang. I've tried the code you mentioned, but that still just brings up the empty email box. I had a feeling I'd need a server-side script to do what I wanted but again, I know very little about this... *rueful grin*

blang




msg:3872273
 2:21 pm on Mar 17, 2009 (gmt 0)

In reviewing your markup, I noticed a problem. You have an unterminated string:
<form name="omaform" action="mailto:email@address.com?subject="From the suggestion box">

Notice that? You start to wrap the mailto: string in "double quotes", then open the subject string in "double quotes" as well. You need to do something like this instead:


<form name="omaform" action="mailto:email@address.com?subject='From the suggestion box'">

Notice the difference? The 'single quotes' that wrap the subject line string are enclosed by the "double quotes" wrapping the entire mailto: string.

Don't forget to add the method and enctype attributes I mentioned!

If you need further assistance building a proper mail form that submits to a server-side script, please let us know.

Maledicta




msg:3872332
 3:10 pm on Mar 17, 2009 (gmt 0)

Thanks Blang, I hadn't noticed that in my tizzy about the rest of it! I'm so used to just using " after a = :-D

But I would love some help with the server-side script and form, if you wouldn't mind...cheers!

blang




msg:3872399
 4:16 pm on Mar 17, 2009 (gmt 0)

But I would love some help with the server-side script and form, if you wouldn't mind...cheers!

Sure; the forums here are a great place to get help on that. If you need personalized help, you can send me a PM (sticky mail on my profile) and we can open a dialog into getting you setup.

rocknbil




msg:3872672
 8:22 pm on Mar 17, 2009 (gmt 0)

Another negative to any "mailto" approach: this will only work if the user has, and uses, an offline client such as Outlook, Eudora, Thunderbird, etc. The browser executes the default mail program on the computer and opens a new email with the to: and subject: populated (you can also populate body.)

But if someone uses an online mail service, such as Yahoo, Gmail, etc., this won't work. It will open the default mail client and most likely confuse the user.

blang




msg:3872805
 10:56 pm on Mar 17, 2009 (gmt 0)

Excellent point. I myself had a hard time when testing the markup on this one! Some users could have the Yahoo! or Google toolbars and thus have their web client set as their default, but overall a CGI script processing the form is best.

Maledicta




msg:3873042
 9:11 am on Mar 18, 2009 (gmt 0)

Oh I didn't realise the mailto: attribute automatically opened up the email anyway. That was my problem then! See, I'm a complete newb at anything other than HTML or CSS, and I'm only self-taught in both of those. Blang, I've sent you a sticky, thanks :-)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved