(insert Noob disclaimer here and yes I googled this...)

I am having a problem inserting a form value into a CCK node field. I have been developing on drupal for about 2 months now and I am just getting the hang of it...

However, I am having an issue when I try to pass a form variable into a CCK field 'field_staff_member' here is the code for the module I am using:

function custom_staffschedule($date, $name) {
	return drupal_get_form('custom_staffschedule_form', $date, $name);
}
function custom_staffschedule_form($date, $name) {
	$form['title'] = array(
		'#type'  => 'textfield',
	);
	$form['date'] = array(
		'#type' => 'textfield',
		'#value' => $date,
	);
	$form['field_staff_member'] = array(
		'#type' => 'textfield',
		'#value' => $name,
	);
	$form['submit'] = array(
		'#type'  => 'submit',
		'#value' => 'edit',


	);
	return $form;
}
function custom_staffschedule_form_submit($form_id, $form) {
	global $user;
	$form_id = 'staffschedule_node_form';
	$node = array(
		'uid'  => $user->uid,
		'name' => $user->name,
		'type' => 'staffschedule',
	);
	$form_values = array(
		'title'    => $form['title'],
		'name'     => $user->name,
		'taxonomy' => $form['taxonomy'],
		'field_staff_member' => $form['field_staff_member'],
	);
	watchdog('debug', 'Saving staffschedule from mini node form');
	drupal_execute($form_id, $form_values, $node);
} 

The node does get created, but with a blank entry for the staff_member field.

Am I missing something obvious?

Comments

nevets’s picture

Three things, the first is just so you understand these are not CCK fields, just form fields in you custom form.

The second applies to both the date and staff member fields, you want to use '#default_value' and not '#value'.

And last, from you submit function you appear to be creating a new node type called 'staffschedule', if that is the case you should really read "Create new content-type for Drupal 5.x" in the handbooks.

jjmulletman’s picture

Let me clarify... I created a CCK content type called "staffschedule". It has a field named "staff_member". I would like to build a submit form that dynamically pulls a single cell from a table of values and submits it into this staff_member field. Currently I can pull the data as a default value and see it on the form, but inserting the data into the node field is a no-go. I think I'm missing a critical step on the submission, but I can not figure it out.

I currently use the staffschedule content type in several other ways that work so I would like to keep it.

BTW- I have taken your advice and changed the '#value' to #default_value'.

dagmar’s picture

Hello:

In http://civicactions.com/blog/cck_import_and_update you can see this

Debug the node edit form by placing a print_r($node) in node.module at the top of node_submit, edit node/add/yourtype, submit the form, remove your debugging print_r, then create your values array to match these values.

For autocomplete user reference fields I use

$form_values['field_assign'] => Array (
  '0' => Array ( 
    'user_name' => 'mariano' 
    ) 
  '1' => Array ( 
    'user_name' => 'javier'
    )  
 ); 

But field status is a select text field, then I use

$form_values['field_status'] => Array (
  'key' => 'closed' 
);

Each widget has a diferent way to pass its values
If you use a print_r instruction in node.module you will see how you must build the $form_values array.
Sorry for my english

Bye
Mariano