I know that it should be easy, but currently it doesnt work. In my function I want to get #title of each element in the form. My form is fieldset "add_company". For example, when I try to get #title:

$msg = '';
foreach ($form['values']['add_company'] as $item)
    $msg .= $item['#title'] . ' ';

But I receive nothing.

Second part of question is when i try smth like this:

$value = $form_state['values']['add_company']['offers']['#title'];

I receive "O", but not "Offers".


You can do it like this:

function my_form_validate(OR_SUBMIT)($form, &$form_state)
  $msg = '';
  foreach(element_children($form[FIELDSET_NAME]) as $key => $value) {
    $msg .= $form[FIELDSET_NAME][$value]['#title'] . ' ';
  • Thx, I've checked your solution and it's almost right answer. Not [$key], but [$value]. Please, correct it so I can mark it as right answer.
    – Zi Cold
    Sep 17 '14 at 0:38
  • @ZiCold Hi, thanks for the clarification, I edited my answer.
    – xurshid29
    Sep 17 '14 at 5:24
  • Well, I've marked it as right answer. Thank you for the answer!
    – Zi Cold
    Sep 18 '14 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.