By mpapet on
The main goal of my module is to add some extra information in the user's admin form.
The following code generates a modified user edit form, www.mydomain.com/user/1/edit. There is an action that's fired when a user edits their account info. I want to pass $form['cg_first_name'] to my action. As the action is written, the form data is not passed.
How do I access my form value?
function cg_volunteer_form_alter(&$form, $form_state, $form_id) {
if ($form['#id'] == 'user-profile-form' || $form['#id'] == 'user_profile_form') {
$form['cg_first_name'] = array(
'#prefix' => '<div id = "one_row"><div id = "one_cell">',
'#type' => 'textfield',
'#title' => t('First Name'),
'#maxlength' => 50,
);
}
};
function cg_volunteer_update_contact_action ($form, &$form_state) {
//global $user;
$test_val = $form_state['values']['cg_first_name'];
watchdog('cg_volunteer', 'cg insert might have happened. %stumpy', array('%stumpy' => $test_val), WATCHDOG_NOTICE, $link = NULL);
}
Comments
You just need to add your
You just need to add your action function to the form's submit array in hook_form_alter(). Just add this line after you declare $form['cg_first_name']:
That should do it
Wrong Call and More
In theory, that API called named almost anything should work. In practice, on the user/1/edit page that does not work.
That's why I'm using an action to fire off my routine. The action function is called, but I have no reference to form data. I *NEED* the form data from my example.
Maybe I'm not understanding
Maybe I'm not understanding the problem, but I've just put your code into a module, added the submission handler to the form as I suggested and it works absolutely fine. I visit user/1/edit and the First Name field is there, and in the cg_update_volunteer_update_action function I print out the $form_state['values'] array which contains cg_first_name as a key. The value in cg_first_name is the correct value that was submitted in the form.
If I've misunderstood let me know and I'll try to help further
Thanks!
Thanks for checking that. There's got to be something wrong with my drupal installation then because it doesn't work for me.
I'll start over and see if I can repeat the error.