Closed (fixed)
Project:
Content Construction Kit (CCK)
Version:
6.x-2.6
Component:
General
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
15 Jan 2010 at 22:40 UTC
Updated:
13 Feb 2010 at 01:20 UTC
I am performing a form_alter on a node/add form for a CCK type name service _request.
<?php
function addSR_form_service_request_node_form_alter(&$form, $form_state) {
if (arg(0) == 'user' && is_numeric(arg(1))) {
$account = arg(1);
$club = 2589;
$form['field_sr_account'] = array( '#type' => 'hidden',
'#value' => $club
);
}
}
The form alter is working, because in the HTML source, the input is "Hidden" and it's value is "2589" - However, when the field is submitted to the database, the column in the content_type_service_request is "2" instead of "2589" - I have tried this with several different numbers, and it always yields the first number of the variable.
-The column type in DB is integer(4)
-I have tried #default_value as well
Comments
Comment #1
markus_petrux commentedThe bug is in your code, not in CCK. So this is support request here. ;-)
You should take into account the delta of the fields. Fields in the form are often organized into arrays (keyed by delta), where each element is a single item. However, the structure may vary from field to field. In case of doubt, you should do a var_dump() from your implementation of hook_form_alter() to figure it out. Once you know, the structure, then you can change it.
Also, I would not recommend to override the whole element as:
...but to change only the attributes that you really need to change. Otherwise, you'll break the field in the form.
Comment #2
bigplanet commentedOk, I tried adding in [43] before the [0], with [#value] on the end.
I'm trying something like this, but still no go...:
I'm still trying to figure out what went wrong? Is it that I gave it an array, but is was expecting an array of array's?
here is what I get on this field when I do a Vardump.
Comment #3
danielb commentedI'm having a similar problem, I have written a cck widget, and it only saves the first letter
this thread didn't help, I already understand there are deltas, but it's still confusing since it seems this decision is being made by cck not by me
Comment #4
danielb commentedUh ok I fixed it
my form element module normally sets the value like this in the validation step:
$element['#value'] = $the_bloody_value;
now it has to be
$element['#value'] = array('value' => $the_bloody_value);
bit strange, but ok...
except that will ruin my widget for non-cck purposes, i think i need a seperate validation callback for cck, since there is nothing in the $element that explicity says "I'm a CCK field".