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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | ajax-dirtyforms.diff | 3.26 KB | galaxor |
| ajax-nonscript-fallback.diff | 3.38 KB | galaxor |
Comments
Comment #1
galaxor commentedbtw, 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.
Comment #2
galaxor commentedThe 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.
Comment #3
j_ten_man commentedWow, that's some patch. My solution was to add this to the very top of ajax_submitter:
Maybe this will have other effects, but seems a lot simpler...
Comment #4
djbobbydrake commentedSubscribing
Comment #5
djbobbydrake commentedTried the solution posted in #3 and seems to work. Thoughts?
Comment #6
brendoncrawford commentedIs there a consensus on which patch I should apply?
Comment #7
djbobbydrake commented@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.
Comment #8
galaxor commentedI 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.
Comment #9
brendoncrawford commentedFixed, thanks to cluke009's code over at the github page.
Comment #10
brendoncrawford commentedhttps://github.com/brendoncrawford/drupal-ajax/pull/2