私はこれらのフォーラム全体を検索し、さまざまな解決策を試しましたが、私のフォームで姓、名を検証する方法を見つけることができません名前と電子メールフィールドは、その後にリダイレクトされます。私はどちらか一方にすることができますが、両方ではありません。フォームは検証またはリダイレクトしますが、両方ともではありません
以下は私のコードです。私はJavaScriptに新しいんだけど、私は私がこの仕事を持つに近いと思う:あなたは通常、あなたの提出関数内$("#signupForm").submit(...
提出する機能をお使いの検証を実行する必要があります
<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>
必要であれば、私は以下にそれを変更したが、それはまだ $(「#のsignupForm」)を働いていないリダイレクト。(関数(提出することができますイベント){ \t \t event.preventDefault() \t \t $ .validator.setDefaults({ \t \t submitHandler:関数(){ \t \t \t alert( "submitted!"); \t \t} \t}); 。それは \t \t $( "#のcommentForm")を提出したとき \t $()レディ(関数(){ \t \t //はコメントフォームを検証する(検証)。 \t \t //サインアップフォームを検証以下とからkeyupに \t \t $( "#のsignupForm")を提出({ \t \t \tルールを検証:{ \t \t \t \t FIRSTNAMEを "必須"、 \t \t \t \t LASTNAME: "必須"、 \t \t \t \tメール:{必要 \t \t \t \t \t:真、 \t \t \t \t \tメール:真 \t \t \t \t}、 \t \t \t} ); \t window.location = 'http ...'; \t }); – Vince