First of all, this module looks super. Only problem is, it's not working for me :(.
I installed and enabled ajax.module and ajax_ui.module. I have a custom form in a module I'm creating called envelopes_online_transaction_form to which I want to add ajax submit. To accomplish that I added this to the form function:
$form['#ajax'] = array(
'enabled' => TRUE
);
The ajax javascript files are being loaded, and my form appears to be ajax enabled: I can click the submit button, it changes momentarily to "loading..." text, and some of my callback function's code is executed. However, none of the sql is executed (nothing saved to database), and watchdog logs a php error message as follows:
Type php
Date Wednesday, April 22, 2009 - 16:08
User magjor
Location http://localhost/envelopes_online_draft1/transactionform
Referrer http://localhost/envelopes_online_draft1/transactionform
Message Missing argument 3 for ajax_validator(), called in C:\xampp\htdocs\envelopes_online_draft1\includes\form.inc on line 766 and defined in C:\xampp\htdocs\envelopes_online_draft1\sites\all\modules\drupal-contrib\ajax\ajax.module on line 390.
Severity error
Hostname 127.0.0.1
Operations
Here is the complete code of the my form's submit function:
function envelopes_online_transaction_form_submit($form, &$form_state) {
dsm($form);
dsm($form_state);
global $user;
$date = strtotime($form_state['values']['date']); // Convert to unix timestamp
$amount = $form_state['values']['amount'];
$description = $form_state['values']['description'];
$from_envelope = $form_state['values']['transaction_info']['from'];
$to_envelope = $form_state['values']['transaction_info']['to'];
// Withdrawal
if ($from_envelope AND !$to_envelope) {
envelopes_online_withdraw($date, $amount, $description, $from_envelope, $user->uid);
}
// Deposit
elseif ($to_envelope AND !$from_envelope) {
envelopes_online_withdraw($date, $amount, $description, $to_envelope, $user->uid);
}
// Transfer
else {
envelopes_online_transfer($date, $amount, $description, $from_envelope, $to_envelope, $user->uid);
}
-the dsm calls do work (they appear immediately when the form is submitted, via ajax).
-the watchdog call within the envelopes_online_withdraw function (code not shown) does work.
-The sql executed within the envelopes_online_withdraw function (code not shown) does nothing. (Of course the code works as expected when ajax is not enabled).
Any help on this would be greatly appreciated. Please let me know what else I can provide that would be helpful.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | formexample.zip | 1.55 KB | jordanmagnuson |
| #3 | envelopes_online.zip | 12.56 KB | jordanmagnuson |
| #1 | envelopes_online_module.txt | 17.1 KB | jordanmagnuson |
Comments
Comment #1
jordanmagnuson commentedI've gone ahead and attached my module code. The form I'm wanting to add ajax to is envelopes_online_transaction_form.
Comment #2
brendoncrawford commentedDavidlerin,
I have tested this with the very latest version of dev and it seems to work fine (not counting the hundreds of ahah_helper warnings). Sometime tonight or tomorrow when the latest dev version updates, please give it a shot. If it still doesnt work, please post the Firebug ajax response here in the bug and reopen.
Comment #3
jordanmagnuson commentedI really appreciate your help Brendon. I tried the latest dev, but am still getting "Missing argument 3" php error in watchdog, and strange behavior when I enable ajax on the form. It is now updating the envelope_transactions db table, but differently than expected (than when ajax is off), and the envelopes table is still not being updated at all. Very strange... it's like different code is being run when ajax is enabled. I'm beginning to suspect that maybe my code is to blame? It seems to work fine when ajax is off though, so I'm quite perplexed.
Will continue to work on this, but will attach the entire module for your review.
As far as the firebug output, you're wanting the response to POST http://localhost/envelopes_online_draft1/transactionform, right? It is:
Comment #4
jordanmagnuson commentedDiscovered that the post information from the form is not complete when ajax is enabled. Checked firebug, and post info is:
Notably, transaction_info[from] is missing completely, which would account for the wrong type of transaction being processed.
Comment #5
jordanmagnuson commentedOkay, I discovered that all the values that weren't being posted when ajax is turned on are values from select fields. I thought that was strange, so I tried creating a new form with nothing but a select field, with code taken directly from the api to factor out typos or whatnot.
Amazingly, the post failed:
When ajax was turned off for the form the value received by the submit function was correct.
Here is the code of the test form:
Any thoughts? I'm sure this module has been successfully tested with select fields, so what could be going on?
Comment #6
jordanmagnuson commentedSearched issues for "select" and found someone else is having trouble with select fields: http://drupal.org/node/440126
Comment #7
jordanmagnuson commentedTo see if the select fields really are a problem I did the following:
Changing status to bug, priority to critical. Attached is the code of the test form module.
Here is the firebug console post response:
Comment #8
jordanmagnuson commentedTook out the select field, and watchdog still logged the "missing argument 3" php error. Seems to happen regardless of the form? Will open a separate issue for that at http://drupal.org/node/443608
P.S. Sorry for all the bombardment. This is a great module, by the way.
Comment #9
brendoncrawford commentedDavidlerin,
It seems the "missing argument" bug and the "select field" bug are unrelated.
Comment #10
brendoncrawford commentedI believe the select field bug might be due to me using a custom jquery.form.js.
Comment #11
brendoncrawford commentedOk, the select issue has now been fixed. dev version should update within 12 hours.
Comment #12
brendoncrawford commented