www.webdeveloper.com
Results 1 to 3 of 3

Thread: email form

  1. #1
    Join Date
    Nov 2004
    Location
    Lisboa, Portugal
    Posts
    71

    email form

    Can anyone please help me?

    I have this form, which works fine, but the problem is that whenever you click the submit button the email is sent even if nothing is written in the form.

    How can i change this into having (maybe with javascript?) it check if the form is filled before submiting.

    <form action="http://blahblah.dll" method="POST">
    <input type=hidden name="mail-to" value="mail@mail.com">
    <input type=hidden name="mail-from" value="text">
    <input type=hidden name="mail-subject" value="text">
    <input type=hidden name="mail-success" value="http://success.htm">
    <div align="left">
    <p>Nome:<br>
    <strong>
    <input name="Nome" type="text" id="Nome" size="20" maxlength="35">
    <br>
    <br>
    </strong> E-mail:<strong><br>
    <input name="E-mail" type="text" id="E-mail" size="20" maxlength="35">
    <br>
    <br>
    <input type="submit" name="Submit" value="Enviar">
    </strong></p>
    </div>
    </form>


    help would be really apreciated, thanks,

    cogumelo

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Its best to validate on both the client and the server.
    Code:
    function checkForm()
    {
       if (document.getElementById('Nome').value == "")
       {
           alert ('Please fill out the form correctly.');
           return false;
       }
       return true;
    }
    ...
    <form ... onsubmit="return checkForm();">
       ...
    </form>
    My Javascript is a bit rusty!

    Do some similar checks from the server (using a server-side language) to ensure the user has not bypassed the JavaScript validation.

    Regards.

  3. #3
    Join Date
    Nov 2004
    Location
    Lisboa, Portugal
    Posts
    71
    thanks for the quick answer!

    regards,
    cogumelo

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles