2017-06-23 6 views
0

Ich habe überall in diesen Foren gesucht und eine Reihe von verschiedenen Lösungen ausprobiert, aber ich bin nur nicht in der Lage, einen Weg zu finden, um mein Formular zu validieren den Vornamen, Last Name und E-Mail-Felder, während später weitergeleitet wird. Ich kann es dazu bringen, das eine oder das andere zu tun, aber nicht beides.Formular wird entweder validieren oder umleiten, aber nicht beide

Unten ist mein Code. Ich bin neu in Javascript, aber ich glaube, ich bin in der Nähe, diese Arbeit zu haben:

<script> 
    $.validator.setDefaults({ 
     submitHandler: function() { 
      alert("submitted!"); 
     } 
    }); 

    $().ready(function() { 
     // validate the comment form when it is submitted 
     $("#commentForm").validate(); 

     // validate signup form on keyup and submit 
     $("#signupForm").validate({ 
      rules: { 
       firstname: "required", 
       lastname: "required", 
       email: { 
        required: true, 
        email: true 
       }, 

    }); 

    $("#signupForm").submit(function(event){ 
     window.location = 'http://www.lifebridgehealth.org/campaign/newneighborsdownload.aspx'; 
    }); 
    </script> 

</script> 

    <style> 
    #commentForm { 
     width: 500px; 
    } 
    #commentForm label { 
     width: 250px; 
    } 
    #commentForm label.error, #commentForm input.submit { 
     margin-left: 253px; 
    } 
    #signupForm { 
     width: 670px; 
    } 
    #signupForm label.error { 
     margin-left: 10px; 
     width: auto; 
     display: inline; 
    } 
    #newsletter_topics label.error { 
     display: none; 
     margin-left: 103px; 
    } 
    </style> 



<body> 
<div id="main"> 
    <form class="cmxform" id="commentForm" method="get" action=""> 
     <fieldset> 
      <p> 
      <input type="hidden" class="reference" id="HC4__Inquiry__c.RecordTypeId" name="HC4__Inquiry__c.RecordTypeId" value="01246000000tqltAAA" /> 
    <input type="hidden" class="picklist" id="HC4__Inquiry__c.HC4__Status__c" name="HC4__Inquiry__c.HC4__Status__c" value="Open" /> 
    <input type="hidden" class="string" id="HC4__Inquiry__c.HC4__Subject__c" name="HC4__Inquiry__c.HC4__Subject__c" value="DG_LBH_PRIM_NewMovers_CY17 form submission" /> 
    <input type="hidden" class="picklist" id="Patient.LeadSource" name="Patient.LeadSource" value="Web Form: DG_LBH_Primary Care_New Movers" /> 
    <input type="hidden" class="picklist" id="Patient.HC4__MostRecentLeadSource__c" name="Patient.HC4__MostRecentLeadSource__c" value="Web Form: DG_LBH_Primary Care_New Movers_FY17" /> 
    <input type="hidden" class="string" id="DemandConnectForm" name="DemandConnect.Form" value="DG_LBH_PRIM_NewMovers_CY17" /> 
    <label class="string" id="Patient.FirstName_label" for="Patient.FirstName">First Name</label> 
    <input type="text" class="string" id="Patient.FirstName" name="Patient.FirstName" value="" required/><br/> 
    <label class="string" id="Patient.LastName_label" for="Patient.LastName">Last Name</label> 
    <input type="text" class="string" id="Patient.LastName" name="Patient.LastName" value="" required/><br/> 
    <label class="email" id="Patient.Email_label" for="Patient.Email">Email</label><input type="text" class="email" id="Patient.Email" name="Patient.Email" value="" required/><br/> 
    <label class="string" id="Patient.PostalCode_label" for="Patient.PostalCode">Mailing Zip/Postal Code</label> 
    <input type="text" class="string" id="Patient.PostalCode" name="Patient.PostalCode" value="" /><br/> 
    <label class="phone" id="Patient.Phone_label" for="Patient.Phone">Home Phone</label> 
    <input type="text" class="phone" id="Patient.Phone" name="Patient.Phone" value="" data-fv-field="phonenumber"/><br/> 
    <label class="phone" id="Patient.MobilePhone_label" for="Patient.MobilePhone">Mobile Phone</label> 
    <input type="text" class="phone" id="Patient.MobilePhone" name="Patient.MobilePhone" value="" data-fv-field="phonenumber"/><br/> 
    <label class="picklist" id="HC4__Inquiry__c.HC4__PreferredContactMethod__c_label" for="HC4__Inquiry__c.HC4__PreferredContactMethod__c">Preferred Contact Method</label> 
    <select type="picklist" class="picklist" id="HC4__Inquiry__c.HC4__PreferredContactMethod__c" name="HC4__Inquiry__c.HC4__PreferredContactMethod__c" /> 
    <option value="Home Phone">Home Phone</option> 
    <option value="Mobile Phone">Mobile Phone</option> 
    </select> 
    <br/> 
    <label class="picklist" id="HC4__Inquiry__c.Best_Time_to_Reach_You__c_label" for="HC4__Inquiry__c.Best_Time_to_Reach_You__c">Best Time to Reach You</label> 
    <select type="picklist" class="picklist" id="HC4__Inquiry__c.Best_Time_to_Reach_You__c" name="HC4__Inquiry__c.Best_Time_to_Reach_You__c" /> 
    <option value="Morning">Morning</option> 
    <option value="Afternoon">Afternoon</option> 
    <option value="Evening">Evening</option> 
    </select> 
    <br/> 
     <label class="boolean" id="HC4__Inquiry__c.Call_Me_Back_to_Schedule_an_Appointment__c_label" for="HC4__Inquiry__c.Call_Me_Back_to_Schedule_an_Appointment__c">Please Call Me Back to Schedule an Appointment</label> 
    <input type="checkbox" class="boolean" id="HC4__Inquiry__c.Call_Me_Back_to_Schedule_an_Appointment__c" name="HC4__Inquiry__c.Call_Me_Back_to_Schedule_an_Appointment__c" /><br/> 
    <input type="submit" value="Submit" /> 
     <br/> 

    <label class="boolean" id="Patient.WantstoLearnMoreAboutLBH__c_label" for="Patient.WantstoLearnMoreAboutLBH__c" >Learn More About LBH?</label> 
    <input type="checkbox" class="boolean" id="Patient.WantstoLearnMoreAboutLBH__c" name="Patient.WantstoLearnMoreAboutLBH__c" checked /> 
    <br/> 
      </p> 
      </p> 
     </fieldset> 
    </form> 
</div> 
<script> 
$("#DG_LBH_PRIM_NewMovers_CY17").validate(); 
</script> 
</body> 
</html> 

Antwort

0

Sie sollten Ihre Validierung innerhalb Ihrer aufführen einreichen Funktion $("#signupForm").submit(...

Die einreichen Funktion dann in der Regel entweder zurückgeben muss richtig oder falsch. True löst die Formularübermittlung aus, false verhindert die Übermittlung.

Da Sie anderswo weiterleiten möchten, sollten Sie die Standardfunktionalität vollständig außer Kraft setzen. Tun Sie dies, indem Sie preventDefault für das Submit-Ereignis aufrufen.

$("#signupForm").submit(function(event){ event.preventDefault()...

Dann können Sie Ihre Validierung durchführen und leiten ggf.

+0

Ich habe es an die unten verändert, aber es funktioniert immer noch nicht $ („# signupForm“). Einreichen (function (event) { \t \t Event.preventDefault() \t \t .validator.setDefaults $ ({ \t \t submitHandler: function() { \t \t \t alert ("submitted!"); \t \t} \t}); ( \t $) ready (function() { \t \t // das Kommentar-Formular validieren, wenn es eingereicht wird \t \t $ ("# Kommentarformular") bestätigen();.. \t \t // validieren Anmeldeformular auf keyup und \t \t $ ("# signupForm") einreichen validieren ({ \t \t \t Regeln:. { \t \t \t \t Vorname: "erforderlich", \t \t \t \t Nachname: "erforderlich", \t \t \t \t E-Mail: { \t \t \t \t \t erforderlich: true, \t \t \t \t \t E-Mail: true \t \t \t \t}, \t \t \t}); \t window.location = 'http ...'; \t }); – Vince

Verwandte Themen