SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member RainFire's Avatar
    Join Date
    Aug 2006
    Location
    Bremen, Germany
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Field Check and Sending Data

    Good Morning all--

    I've been working on putting in a script to make fields in my form required. Pretty easy and standard. However it seems like the form is still sending the data even though the user has been informed of the missing fields, fills them in, and submits again. (This has resulted in a lot of multiple mails all partialy filled in, and not consistently.) Any idea what's going on? I'm not a javascript or forms person so this is a bit baffling to me.

    'Preciate any help.

    Code JavaScript:
    <SCRIPT LANGUAGE="JavaScript">
     
    <!-- Begin
    function verify() {
    var nachricht = "Sie müssen die folgende Felder ausfüllen: ";
    if (document.Formular.nachname.value=="") {
    nachricht = nachricht + " - Nachname";
    }
    if (document.Formular.firma.value=="") {
    nachricht = nachricht + " -  Firma";
    }
    if (document.Formular.mail.value=="") {
    nachricht = nachricht + " -  Email";
    }
    if (document.Formular.tel.value=="") {
    nachricht = nachricht + " -  Telefon";
    }
    if (document.Formular.strasse.value=="") {
    nachricht = nachricht + " -  Strasse & Nr.";
    }
    if (document.Formular.plz.value=="") {
    nachricht = nachricht + " -  PLZ";
    }
    if (document.Formular.land.value=="") {
    nachricht = nachricht + " -  Land";
    }
    //alert if fields are empty and cancel form submit
    if (nachricht == "Sie müssen die folgende Felder ausfüllen: ") {
    document.Formular.submit();
    }
    else {
    alert(nachricht);
    return false;
       }
    }
    //  End -->
    </script>

    Code HTML4Strict:
    <form name="Formular" action="/cgi-bin/mailmanager.pl" method="post">
    <INPUT type=hidden name="recipient" value="download@plantafel.net">
    <INPUT type=hidden name="subject" value="Download Anforderung infoBoard V2.0 von Projektplanung Kampagne">
    <table width="840px" style="border: 1px dashed #302E78;" cellspacing="4">
    <tr>
    <td colspan="2" class="form-heading" style="background: #302E78; color: #ffffff; font-size: 14px; font-weight: bold; padding: 5px;" width="50%">Ihr Info</td>
    <td colspan="2" class="form-heading" style="background: #302E78; color: #ffffff; font-size: 14px; font-weight: bold; padding: 5px;">Adresse</td>
    </tr>
     
    <tr>
    <td></td>
    <td>
    <select name="Anrede">
    <option>----- Anrede -----</option>
    <option>Frau</option>
    <option>Herr</option>
    </select>
    </td>
     
    <tr>
    <td><label for="nachname">Nachname*</td>
    <td><input id="nachname" name="nachname" type="text" /></td>
    <td><label for="strasse">Strasse Nr.*</td>
    <td><input id="strasse" name="strasse" type="text" /></td>
    </tr>
     
    <tr>
    <td><label for="firma">Firma*</label></td>
    <td><input id="firma" name="firma" type="text" /></td>
    <td><label for="plz">PLZ* / Stadt*</label></td>
    <td><input id="plz" name="plz" type="numeric" size="5" maxlength="5" /> / <input id="stadt" name="stadt" type="text" size="18" /></td>
    </tr>
     
    <tr>
    <td><label for="mail">E-Mail*</label></td>
    <td><input id="mail" name="mail" type="text" /></td>
    <td><label for="land">Land*</label></td>
    <td><input id="land" name="land" type="text" /></td>
    </tr>
     
    <tr>
    <td><label for="tel">Telefon*</label></td>
    <td><input id="tel" name="tel" type="text" /></td>
    <td><label for="fax">Fax</label></td>
    <td><input id="fax" name="fax" type="text" /></td>
    </tr>
     
    <tr>
    <td colspan="2" class="form-heading" style="background: #302E78; color: #ffffff; font-size: 14px; font-weight: bold; padding: 5px;">Optionen</td>
    <td colspan="2" class="form-heading" style="background: #302E78; color: #ffffff; font-size: 14px; font-weight: bold; padding: 5px;">Raum für besondere Anliegen, Fragen oder Wünsche:</td>
    </tr>
     
    <tr>
    <td colspan="2" style="padding-left: 20px;">
    <ul class="form_list"><h1 class="blue">Wir suchen nach:</h1>
    <li><input name='suche' TYPE='radio' class="suche1" VALUE='Plantafel_Mitarbeiter'> einer Planungstafel für Personaleinsatz</li>
    <li> <input name='suche' type='radio' class="suche2" value='Projektplanung'> einem einfachen Projektplanungsprogramm</li>
    <li><input name='suche' type='radio' class="suche3" value='Auftrag_MAschinenplanung'> einer Auftrags- und Maschinenplantafel</li>
    </ul>
     
    <ul class="form_list"><h1 class="orange">Ich möchte gerne zusätzlich:</h1>
    <li><input name='Kostenlose Angebote' class="zusatzlich1" type='checkbox'> weitere kostenfreie Angebote</li>
    <li><input name='Beispiel &uuml;bersenden' class="zusatzlich2" type='checkbox'> mein Beispiel übersenden</li>
    <li><input name='Software per Post' class="zusatzlich3" type='checkbox'> Demo-Software per Post</li>
    </ul>
    </td>
    <td colspan="2" align="center"><textarea cols="46" rows="15">
    </textarea>
    </td>
    </tr>
     
     
    <tr>
    <td colspan="4" style="border-top: 5px solid #302E78; padding: 10px; text-align: right;">
    <input class="submit" type="submit" value="abschicken" style="padding: 5px;" onclick="verify();">
    <input type="hidden" name="redirect" value="../infoBoard_Server/Projektplanung/danke_server.html" />
    </td> 
    </tr>
    </table>
    </form>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    onclick="verify();" ?!?

    Code Javascript:
    <input class="submit" type="submit" value="abschicken" style="padding: 5px;" onclick="verify();">

    What happens when people press enter instead, or tab to the submit button and press space?

    Try instead using the onsubmit event.

    Code Javascript:
    <form name="Formular" action="/cgi-bin/mailmanager.pl" method="post" onsubmit="return verify()">

    Then the verify function can return false to cancel the submit (if an invalid field is there) or it can return true to allow the form to be submitted.


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
  •