I’m trying to use the inline subscribe Ajax form but when I enter an email address and click subscribe, Ajax returns the contents of the subscribe page instead of the success message and does not add the email address to the list. Also, the subscriber page content shows an error stating that the email address is missing Here is my form and my jquery followed by the text of return data:
<form method="post" action="" name="subscribeform" id="subscribeform" enctype="multipart/form-data">
<table border=0>
<tr>
<td><div class="required">Email: </div></td>
<td class="attributeinput"><input type="text" name="emailadd" id="emailadd" value="" size="20" autocomplete="on"></td>
<td><input type="hidden" id="subscribe" name="subscribe" value="subscribe"/> <button class='button' onclick="if (checkform()) {submitForm();} return false;" >Subscribe</button></td>
</tr>
</table>
<input type=hidden name="htmlemail" value="1"> <input type="hidden" name="list[1]" value="signup" /> <div id="result" style="color: red;"></div>
</form>
function checkform() {
re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!(re.test(jQuery("#emailadd").val()))) {
jQuery("#result").empty().append("Please enter a valid email address");
jQuery("#emailadd").focus(); return false;
}
return true;
}
function submitForm() {
successMessage = 'Thank you for your registration. Please check your email to confirm.';
data = jQuery('#subscribeform').serialize();
jQuery.ajax( {
type: 'POST',
data: data,
url: 'https://mysite.com/lists/?p=subscribe&id=1',
dataType: 'html',
success: function (data, status, request) {
jQuery("#result").empty().append(data != '' ? data : successMessage); jQuery('#emailadd').val('');
},
error: function (request, status, error) {
alert('Sorry, we were unable to process your subscription.');
}
});
}
Subscribe to our email list
- required fields are marked red
Please enter a valid email address
The following required values are missing: Email addresses you entered do not match
Email address *
Confirm your email address *
Unsubscribe