I have an ajax form set up for my EE contact form which requires that the email and message field be filled in. I need to have "name" and "subject" required too. Please help
// Contact form to use AJAX.
$(document).ready(function()
{
/* helper function to display a message describing the results of the form submit */
function displayAjaxMessage(message)
{
$("#ajax-message").html(message);
$("#ajax-message").fadeIn(1000);
}
/* attach a submit handler to the contact form. By default, EE generates the ID "contact_form" */
$("#contact_form").submit(function(event)
{
/* stop the contact form from submitting normally */
event.preventDefault();
/* hide any left over message from a previous submit */
$("#ajax-message").hide();
/* send the form data using post and check the results for any errors*/
$.ajax(
{
url: "/",
type: "post",
dataType: "html",
data: $(this).serialize(),
/* If there was some kind of an AJAX error, display an appropriate message or take some other action of your choice */
error: function(jqXHR, textStatus, errorThrown)
{
displayAjaxMessage("Sorry, a mistake in form");
},
/* parse the HTML returned by EE to see if they forgot to enter an email address or a message.
If so, the HTML will contain a specific error string we can match, and then we can display our own message */
success: function(html, textStatus, jqXHR)
{
if (html.match(/<title>Error<\/title>/))
{
var error = $(html).find('ul li:first').text();
if (error == "A valid sender email is required")
{
displayAjaxMessage("Vennligst oppgi en gyldig mailadresse");
}
else if (error == "Email Message is Required")
{
displayAjaxMessage("Legg inn en melding");
}
}
else
{
displayAjaxMessage("Takk for at du kontakter oss");
}
}
});
});
});