0

I need to pass an array with all the fields (with their values) from a form from the submit function to a rules_invoke_event.

to do this I'm calling a get_fields() function, in this function I have acces to the form and form_state objects. Just wondering how I could loop through one of these with a foreach to get an array with the pairs?

function get_fields($form, $form_state)
  $fields = array()
  foreach(element in form)
  { 
    $fields[$element[key]] = element[value];
  }
  return$ fields
}

something like this but with correct syntax?

Help would be greatly appreciated :)

1

This might work.

function get_fields_this_step($form_state) {
    $fields = array();
    foreach($form_state['values'] as $key=>$value){
        $fields[$key] = $value;
    }
    unset($value);
    return $fields;
}
0

You are very close, simply dpm($form_state) (if you have Devel Module installed) or print_r it. You'll find there all the form values you're needing. Loop over the array that contains form values inside the $form_state array.

-1

Or you can just use

$form_state['values']['submitted_tree']

which is already formatted in the way you want. I'm not sure if this only applies to forms created with the webform module, but worth a shot!

  • This doesn't seem to return anything on my end. Where did you get this from? – Weboide Jan 21 '14 at 18:50

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.