If the user has disabled javascript, or is using a browser that doesn't support javascript, then it should fall back to submitting like a regular form. Instead, the ajax module submits, and the user is treated to a textarea full of json.

What we should do is this: Print out a hidden field called "ajax_ajax_submit" when we send the html to the browser. The value of this field is 0. Let the javascript change the value of the field to 1. When the form is submitted, if ajax_ajax_submit is still 0 (most likely because the user doesn't have javascript), then the ajax_submitter and ajax_validator will bow out and let the normal processing happen. If it has been set to 1 (most likely because the user has javascript enabled), then we print out the textarea full of json.

A side effect is that this lets javascript in other modules control whether a form will be submitted ajaxily or regularly, by changing the value of ajax_ajax_submit.

Anyway, I have a patch that does this.

Comments

galaxor’s picture

btw, if you want another module's javascript to disable ajax submission, you'll have to do both of these things:
1. Set ajax_ajax_submit to 0 -- this will let the server return the non-ajax content.
2. Remove the 'ajax-trigger' class from the button. This will let the client know to submit the form and not expect ajax content from the server.

galaxor’s picture

StatusFileSize
new3.26 KB

The above patch doesn't work well with DirtyForms; all forms will be counted as dirty. No matter what, if the user tries to close the window or navigate away, they will see a message that they've made changes that are not saved. This is because we have javascript changing ajax_submit_submit from 0 to 1.

This new patch is the same as the old, except that we add a "dirtyforms-exclude" css class to ajax_submit_submit, causing this problem to go away.

j_ten_man’s picture

Wow, that's some patch. My solution was to add this to the very top of ajax_submitter:

function ajax_submitter(&$form, &$form_state) {
  if (!isset($_POST['drupal_ajax'])) {
    return;
  }
  ...
}

Maybe this will have other effects, but seems a lot simpler...

djbobbydrake’s picture

Subscribing

djbobbydrake’s picture

Tried the solution posted in #3 and seems to work. Thoughts?

brendoncrawford’s picture

Status: Needs review » Postponed (maintainer needs more info)

Is there a consensus on which patch I should apply?

djbobbydrake’s picture

@brendoncrawford - Until a more complete solution has been agreed upon, I'd go with #3, since it's much less code and much simpler. Been using it on a site with millions of hits a day and haven't had issues.

galaxor’s picture

I haven't tried the patch from #3, but if it works, it works. I did mine the way I did because I wasn't aware of that post variable.

brendoncrawford’s picture

Status: Postponed (maintainer needs more info) » Fixed

Fixed, thanks to cluke009's code over at the github page.

brendoncrawford’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.