SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help for a form

    Hello,

    I need to create a form on a web site that allows the user to enter
    their name, email address, mailing address and comments and then have that information go to my email account when they hit the submit button. I am not sure how to write the code to make it work.

    Also, if I wanted the information to also be usable in Excel how would that work?

    Thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,494
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)

    js form mail

    Hi bookworks, welcome to the forums,
    AFAIK the best you can do using javascript alone is to have the form populate the "to", "subject" and "body" fields and call up the user's email client to send the email. Something like
    HTML Code:
    <form action="mailto:[your emaill address here]">
    <input name="subject" type="text">
    <input name="body" type="text">
    <input type="submit" value="submit">

  3. #3
    SitePoint Zealot MajorTom's Avatar
    Join Date
    Aug 2007
    Location
    Planet earth
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll need to use PHP or some other server side scripting language is you want to return CSV formatted datavia email from an html form. There's no real way to do it in JavaScript but Mittineague's suggestion will work - no bells and whistles but it will work without server side scripting.

  4. #4
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I think I didn't ask the question clearly...sorry, new at this. The form I need to create is a page with in the web site so the user can leave their information, since I don't know how to program for a database at this time, I would like the form's info to be sent to an email address instead when they hit submit.

    I saw a form on a site that is basically what I need. It has this code in it, but I am not sure how I would re-write it to work for me.

    <script language=JavaScript>
    function validate(theform){
    var form_error=false
    var error_message = ""
    if (theform.name.value == "") {
    error_message += "Please enter Name.\n\n"
    form_error = true
    }
    if (theform.email.value == "") {
    error_message +="Please enter Email address.\n\n"
    form_error = true
    }
    if (theform.email.value.indexOf ('@',0) == -1 || theform.email.value.indexOf ('.',0) == -1)
    {
    error_message +="The Email field requires a \"@\" and a \".\" to be used.\n Please re-enter your E-mail address.\n\n"
    form_error = true
    }

    if (form_error){
    alert(error_message)
    return false
    }
    }

    Then it has the form input part this is just a snipet:

    <table border="0" align="left" cellpadding="3" cellspacing="0"><form action="contact.php" method="post" name="form1" id="form1" onsubmit="return validate(this);">
    <tr>
    <td bgcolor="#FFFFFF">Name/td>
    </tr>
    <tr>
    <td bgcolor="#FFFFFF"><input name="name" type="text" id="name" size="40" /></td>
    </tr>
    <tr>

    <td bgcolor="#FFFFFF">Email/td>
    </tr>
    <tr>
    <td bgcolor="#FFFFFF"><input name="email" type="text" id="email" size="40" /></td>
    </script><title>Starn Vision and Starn Vision Affiliates</title>
    </tr>

    <input type="submit" name="Submit" value="Send" class="btn" />
    &nbsp;
    <input type="reset" name="Submit2" value="Reset" class="btn" />
    <input name="btn_contact" type="hidden" id="btn_contact" value="1" />
    </div></td>
    </tr></form>
    </table>

    And this code too:

    <script language="JavaScript" type="text/javascript">mailme("generalinfo","starnvision","com","","");</script>

    I am not sure how it works-maybe there is a database involved? I don't have to have that part-just for the user to fill out the form and the form to be submitted and that goes to the web owner's email address. Thank you..again.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    This here is all you need to submit a form to an email address. No javascript, just html.

    Code HTML4Strict:
    <form action="mailto:person@domain.com">
        Name:<br />
        <input name="name" type="text"><br />
        Email address<br />
        <input name="email" type="text"><br />
    	Postal address<br />
        <textarea name="postal" rows="4"></textarea><br />
    	Comments<br />
    	<textarea name="comments" rows="6" cols="40"></textarea><br />
        <input type="submit" value="Submit">
    </form>

  6. #6
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much!!

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,494
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)

    email form info

    The javascript validate() function makes sure
    1. the "name" field is not empty
    2. the "email" field is not empty
    3. the "email" field has a "@" and a "." in it

    The form (which has a closing </script> tag with no opening tag?) sends the form's input from "name", "email", and "btn_contact" as $_POST variables to "contact.php". In your case, the "contact.php" file could use the mail() function although it could also write to a file and/or INSERT to a database too.
    As for
    HTML Code:
    <script language="JavaScript" type="text/javascript">mailme("generalinfo","starnvision","com","","");</script>
    without seeing the mailme() function there's no way to know exactly what it does.


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
  •