We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Ajax channel form inline validation

How Do I?

Mohammed's avatar
Mohammed
6 posts
7 years ago
Mohammed's avatar Mohammed

Hi,

I have a channel form that allows guests to adds entries to a channel (they post requests for content). The form submission is handled through jquery $(‘#formId’).ajaxForm() with json=”yes” on the form, and validation is set to inline in the form tag (error_handling=”inline”). However I can’t get form validation to work. If the form has no validation errors it submits correctly, but, if it contained validation errors then the user get a new page with the Json output.

The form looks like this:

{exp:channel:form channel="channelName" class="request" id="request" error_handling="inline" json="yes" rules:name="required|min_length[5]" rules:phone="required|min_length[5]|integer" rules:email="required|email"}
     <ul>
          <li>
               <label for="name">{phrase:request_name}:</label>
               <input name="name" id="name" type="text">
               {error:name}
          </li>
          <li>
                <label for="phone">{phrase:request_phone}:</label>
                <input type="text" name="phone" id="phone">
                {error:phone}
          </li>
          <li>
                <label for="email">{phrase:request_email}:</label>
                <input type="text" name="email" id="email">
                {error:email}
         </li>
     </ul>
     <input type="submit" value="{phrase:request_send}" id="submit">
{/exp:channel:form}

And the scripts that handles submission looks like this:

$('#request').ajaxForm({
     dataType: 'json',
     success: function(data) {
          if (data.success)
               $("#submit").addClass('success').attr('value', 'Request sent');
          else
               $("#submit").addClass('error').attr('value', 'Error');
});

Any ideas?

Thanks.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.