Hello,

I am trying to update a cck field (price) when the user changes another field(product). Currently I am doing this using form_alter, but the change is not instant - I need to put the price field in the next step of a multistep form.

Is this module designed to do something like this? If so, could someone explain how. Here is the hook_form_alter code I'm using now:

function mysite_helper_form_alter(&$form, $form_state, $form_id) {
  // Normally a switch is used because you may want to alter more than
  // one form and it is easy to add a new case for each form.
  switch ($form_id) {
    // This is our form ID.
  		case 'order_detail_node_form':
	// This fills in the price in the form based on the style selected 
		$bug = $form[field_stylenumber_ref]['#value'][0][nid];
		$sql =db_query('SELECT content_type_prices.field_bsrp_value FROM {content_field_stylenumber_ref} INNER JOIN {content_type_prices} ON (content_field_stylenumber_ref.vid = content_type_prices.vid) WHERE content_field_stylenumber_ref.field_stylenumber_ref_nid =%f',$bug);
		  $bsrp = db_result($sql);
    	$form['field_price_per_unit'][0]['#default_value']['value'] = $bsrp;
      
	break;
  }
}

Thank you.

Comments

gapa’s picture

Hi,
I'm using this module in a similar way as you want to. The thing is to assign ajax trigger (I think you will have to use "change" for javascript event) to the field you are changing (product field). Then use hook_ajax_trigger instead of hook_form_alterer. The code could probably be used with small modification.

br,
gapa

dogboy72’s picture

Thanks for the help. I am using the Node Relationship module to reference products. Currently the code above works in a multistep form where the product is in step 1 and the price(among other things) is in step 2. I'd prefer not to use multistep so hopefully I can get this code working.

kenorb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.