I'm writing a module using FAPI. The form aspects are fine, including fetching data from my database. I'm using entity metadata wrapper to fetch the field data and page arguments to select the specific entityform submission I'm pulling from.

The issue is that simply adding ajax functionality to any textfield gives a 500 error. Doesn't matter what (or anything) I have in the callback function, it bombs. The error messages don't give me enough info (AFAICT). I'm trying to respond to the user altering the displayed data to then compute new results and then store those results. I'm not getting past the blur trigger.

Here are the error messages:

An AJAX HTTP error occured. HTTP Result Code: 500. EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. Value at entityform(): ajax. in EntityDrupalWrapper->set() (line 756 of /home/mysite/mysite.dreamhosters.com/sites/all/modules/entity/includes/entity.wrapper.inc).

Strict warning: Only variables should be passed by reference in investment_lineitems_form() (line 48 of /home/mysite/mysite.dreamhosters.com/sites/all/modules/investment_lineitems/investment_lineitems.module).

Here's the code:

 /**
 * Implements hook_form()
 */
 function investment_lineitems_form($form, &$form_state) {
	 
	$itemcounter = 0;
	
	$entityform = array_pop(arg());   //  *** THIS IS LINE 48 REFERENCED IN THE ERROR ***
	
	$wrapper = entity_metadata_wrapper('entityform', $entityform); 
		
	
	foreach ($wrapper->field_inv_account_details as $field_collection_wrapper) {
	  $field_your_percent_a = $field_collection_wrapper->field_inv_your_percent_split_a->value();
	  $itemcounter++;
	  if (!empty($field_item_value)){
		  
	
	$form['edit_your_percent_amount_'.$itemcounter] = array(
		'#type' => 'textfield', //you can find a list of available types in the form api
		//'#title' => 'Item Value '.$itemcounter, //Form the field label
		'#size' => 5,
		'#maxlength' => 5,
		'#value'=>$field_your_percent_a,
		'#required' => FALSE, //make this field required 
		'#ajax' => array(
			'callback' => 'ajax_alert_callback',
		),
		//'#weight' => 5,
	       );
               }
    }
	
  $form['submit_button'] = array(
    '#type' => 'submit',
    '#value' => t('Save Changes'),
	'#weight' => 15,
  );
  
  return $form;  
}

 /**
 * Callback for 'alert'.    USE THIS FOR TESTING AND DEBUGGING
 *
 * @see ajax_command_alert()
 */
function ajax_alert_callback($form, $form_state) {
  //$commands = array();
  //$commands[] = dsm($form_state['triggering_element']); //ajax_command_alert("Alert requested");
  //return array('#type' => 'ajax', '#commands' => $commands);
  
}

Any recommendations or suggestions are very welcome.

Comments

hondaman900’s picture

So, if I comment out the line indicated in the error and replace it with a fixed value, like so:

$entityform = 68; //array_pop(arg());

then the error goes away, so this is something to do with that argument I pass in the URL to use the entityform ID in my wrapper formation.

Any ideas why that would be causing the error - when there's an AJAX callback does that argument get lost/corrupted?