tags:

views:

142

answers:

2

I have a field in a CCK node form that is hidden, and has a default value. What I'm trying to do is, when the user fills out the form, and submits it - I want to take the value of the hidden field and use it for a query.

My question is, how can I get this value? In PHP/HTML the $POST variable can be used. But, how can I do this in drupal?

I'm trying variations of this:

$form['#field_tst_timesheet']['value']

Anyone know how I can get at the value of this field?

Vfillby's answer:

Entering this:

 $ts =  field_tst_timesheet['0']['value'];
 drupal_set_message($ts);

resulted in Parse error: syntax error, unexpected '[' ?

A: 

Not a full answer but I do recall CCK having some oddities when accessing values of the fields directly. I remember having to access the field value like this

field_cck_custom_field['0']['value'].  

Depending on the type of field ['value'] might be ['nid'] or something similar.

If the field value is embedded in the form you may have to use the cck style accessors to get at the form value (that is actually a cck field)

If you don't have an xdebug environment setup one handy way of debugging drupal objects is by using var_export and drupal_set_message like this:

drupal_set_message( '<pre>' . var_export( $form['#field_tst_timesheet']['value'], TRUE ) . '</pre>' );

This should pretty print the object in the drupal messages section.

vfilby
I tried something like this early in my troubleshooting attempts - and received the error above..
cinqoTimo
Have you tried the following? drupal_set_message( '<pre>' . var_export( $form['#field_tst_timesheet']['value'], TRUE ) . '</pre>' );
vfilby
+2  A: 

You're close, but you have the identifiers backwards. Try this instead:

$form['field_tst_timesheet']['#value']

With forms, the key that will get POST-ed is the name attribute of the form element, not the id element.

John Feminella