Hoping someone can help with this. I have a form which has an action attribute. This action attribute enables the user to subscribe to a newsletter when the form is submitted.
What I'm trying to do is only use that action if the user has checked a checkbox giving permission to subscribe to the newsletter. If the checkbox is left unchecked, the form can still be submitted, but will be redirected to a separate URL, disregarding the form's action attribute.
So far this is what I have, I'm not great with javascript so any help would be appreciated.
$('#wifi-capture-form').submit(function(e) {
var wifiConfirm = $(this).attr("data-redirect");
if ($('input.newsletter-checkbox').is(':checked')) {
f24("send", "form", "form.#wifi-capture-form");
}
else (
f24("send", "form", $(this), function(e) {
e.preventDefault
window.location = wifiConfirm;
})
)}
});
});
and the form is
<form name="wifi-capture-form" id="wifi-capture-form" action="http://ift.tt/2CFuOhL" method="post" class="f24form wifi-capture-form" data-redirect="https:http://ift.tt/2D4bHPn">
<label for="fieldName">Name</label><br />
<input id="fieldName" name="cm-name" class="form-control" type="text" />
<label for="fieldEmail">Email</label><br/>
<input id="fieldEmail" class="form-control" name="cm-dkhywr-dkhywr" type="email" required /><br/><br/>
<input type="checkbox" name="newsletter" class="newsletter-checkbox" id="newsletter" value="Subscribe to newsletter"> Subscribe to our newsletter<br/><br/>
<button type="submit" class="btn btn-primary">Submit</button>
Aucun commentaire:
Enregistrer un commentaire