开发者

retrieve cck field for form_alter

开发者 https://www.devze.com 2023-01-08 23:22 出处:网络
I would like to retrieve a cck field \"field_info\" in my form alter to insert into another table when user is submitting. This开发者_如何学C doesn\'t seem to work.

I would like to retrieve a cck field "field_info" in my form alter to insert into another table when user is submitting. This开发者_如何学C doesn't seem to work.

//mymodule_form_alter() implemented
       function mymodule_form_mysubmit{

            $test = $form['field_info']['#value'];
        //insert stuff code
    }

Is there any mistake in the code?


You say module_form_alter() is implemented, but just to confirm, you need to have the following in it:

$form['#submit'][] = 'mymodule_form_mysubmit';

Assuming you do, to get the value of field_info, your submit function should look like:

function mymodule_form_mysubmit($form, &$form_state) {
  $test = $form_state['values']['field_info'][0]['value'];
}

$form_state contains the current state of the form being submitted. CCK always assumes that there could be multiple values for a field, so it always puts things in an array (hence ['field_info'][0]).


I found the solution

        $test = $form['field_info'][0]['#value'];
0

精彩评论

暂无评论...
验证码 换一张
取 消