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 :)

0

3 Answers 3

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!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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