1

It's the first time I've used Ajax with Channel Form so this maybe a newbie question.

I'm loading the template containing my form via AJAX and appending it to a DIV. When the form is submitted I want to show messaging in the same DIV so I'm overriding the default form submit in jQuery but I can't prevent the page from refreshing. If I set the form parameter ajax="yes" then it simply redirects to JSON output.

What am I missing?

Static form ID works fine:

<form id="comment-form">
          <input type="text">
          <button type="submit">Submit</button>
        </form>

Channel Form ID does not work:

{exp:channel:form 
          channel="logbook"
          include_jquery="no"
          include_assets="no"
          datepicker="no"
          class="logbook-add"
          id="comment-form"
          return="/account/manage-logbook-requests/#comments"
          entry_id="{segment_3}"
        }

jQuery code:

$("#comment-form").on('submit', function (e) {
            e.preventDefault();
            console.log('submitted');
        });
0

json="yes" parameter is merely changing format of data output. You will need to add appropriate Javascript code to handle submission and displaying of results.

See example in the docs. You can use it as the base but change code that is producing alert to code that will show success/error message in same div (e.g. using jQuery's .html() function)

| improve this answer | |
  • Hi Yuri, thanks for your comment. The bizarre thing is I have a jQuery event handler preventing the form from submitting but it is not working. If I create a static form with the same ID it does work, but it does not work for the same ID on the Channel Form. I will update my original post with the code. – KoalaKid Nov 25 '15 at 1:09
  • You might be getting some javascript conflict. Check you browser console for errors. – Yuri Salimovskiy Nov 25 '15 at 7:53
  • I think the parameter should be json="yes" not ajax="yes" – mjr Dec 17 '15 at 22:28
  • @mjr, you're right – Yuri Salimovskiy Dec 18 '15 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.