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.

Comments

jordanmagnuson’s picture

StatusFileSize
new17.1 KB

I've gone ahead and attached my module code. The form I'm wanting to add ajax to is envelopes_online_transaction_form.

brendoncrawford’s picture

Assigned: Unassigned » brendoncrawford
Status: Active » Fixed

Davidlerin,

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.

jordanmagnuson’s picture

Version: 6.x-1.13 » 6.x-1.x-dev
Status: Fixed » Active
StatusFileSize
new12.56 KB

I 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:

{ "status": true, "updaters": [  ], "debug": [  ], "messages_error": [  ], "messages_status": [  ], "messages_warning": [  ], "redirect": null, "preview": null, "form_id": "envelopes_online_transaction_form", "options": { "enabled": true } }
jordanmagnuson’s picture

Discovered that the post information from the form is not complete when ajax is enabled. Checked firebug, and post info is:

amount	5

date	4/24/2009

description	

drupal_ajax	1

form_build_id	form-93fc7faffdc3faf33ff6c6f826e317fd

form_id	envelopes_online_transaction_form

form_token	decaa033484637b977bf3b15f51f257d

op	Submit Transaction

transaction_info[transaction_type]	withdrawal

Notably, transaction_info[from] is missing completely, which would account for the wrong type of transaction being processed.

jordanmagnuson’s picture

Okay, 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:

  • The submit function did get the value from the field, but ONLY THE DEFAULT VALUE, regardless of what was chosen
  • Firebug did not show the value posting AT ALL.

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:

	$form['#ajax'] = array(
		'enabled' => TRUE
	);
	$form['feed'] = array(
		'#type' => 'select',
		'#title' => t('Display of XML feed items'),
		'#default_value' => 'title',
		'#options' => array(
			'title' => t('Titles only'),
			'teaser' => t('Titles plus teaser'),
			'fulltext' => t('Full text'),
		),
		'#description' => t('Global setting for the length of XML feed items that are output by default.'),
	);
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit Transaction'),
  );

Any thoughts? I'm sure this module has been successfully tested with select fields, so what could be going on?

jordanmagnuson’s picture

Searched issues for "select" and found someone else is having trouble with select fields: http://drupal.org/node/440126

jordanmagnuson’s picture

Title: Not Working: Missing argument 3 for ajax_validator() » Select fields not working: Missing argument 3 for ajax_validator()
Category: support » bug
Priority: Normal » Critical
StatusFileSize
new1.55 KB

To see if the select fields really are a problem I did the following:

  1. Installed a fresh copy of Drupal 6.10, default configuration.
  2. Installed Ajax 6.x-1.3 module.
  3. Created a very simple module containing a single form, with a select field.
  4. Tested the form without ajax: worked as expected.
  5. Tested the form with ajax: failure:
    1. Default value was passed to the submit function regardless of which option was selected.
    2. Firebug console showed that no value was being posted for the select field.
    3. Watchdog logged the already mentioned "Missing argument 3" php error.

Changing status to bug, priority to critical. Attached is the code of the test form module.

Here is the firebug console post response:

{ "status": true, "updaters": [  ], "debug": [  ], "messages_error": [  ], "messages_status": [ { "id": 0, "value": "Thanks for filling out the form, \x3cem\x3eJordan\x3c/em\x3e" }, { "id": 1, "value": "Feed is, \x3cem\x3etitle\x3c/em\x3e" } ], "messages_warning": [  ], "redirect": null, "preview": null, "form_id": "formexample_nameform", "options": { "enabled": true } }
jordanmagnuson’s picture

Title: Select fields not working: Missing argument 3 for ajax_validator() » Select fields not working

Took 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.

brendoncrawford’s picture

Davidlerin,

It seems the "missing argument" bug and the "select field" bug are unrelated.

brendoncrawford’s picture

I believe the select field bug might be due to me using a custom jquery.form.js.

brendoncrawford’s picture

Ok, the select issue has now been fixed. dev version should update within 12 hours.

brendoncrawford’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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