How to get $form_id based on $form_state for custom form rule? I'm building custom form rule which is having $form_state as rule input parameter, however I would like to use drupal_form_submit() which requires $form_id.

Is it possible to fetch/compute automatically $form_id based on its $form_state to make my rule generic?

Or maybe there is some documentation that explains what $form_state should consist exactly?

My rule is like:

/**
 * Implements hook_rules_action_info().
 */
function rules_forms_rules_action_info() {
  $actions['rules_forms_submit'] = array(
    'label' =&gt; t('Submit the form'),
    'group' =&gt; 'Rules Forms',
    'parameter' =&gt; array(
      'form_state' =&gt; array('type' =&gt; 'form_state', 'label' =&gt; t('Form state')),
    ),
    'base' =&gt; 'rules_forms_action_submit',
    'access callback' =&gt; 'rules_forms_integration_access',
  );
  return $actions;
}

/**     
 * Action: Submit the form.
 */
function rules_forms_action_submit($form_state) {
  // $form_id = ?
  drupal_form_submit($form_id, $form_state);
}


I've checked $form_state and it's a huge (~0,5MB size-like) ArrayObject with the following main keys/properties:

build_info, temporary, programmed, programmed_bypass_access_check, cache, entityform, entityform_form_mode, field, storage, rebuild, rebuild_info, redirect, submitted, executed, method, groups, buttons, input, values, complete form, process_input, invalid_token, triggering_element, submit_handlers, clicked_button
I think the easiest way was to pass $form ArrayObject which has $form_id present. So:

'form' =&gt; array('type' =&gt; 'form', 'label' =&gt; t('Form')),


needed to be added next to $form_state parameter in hook_rules_action_info and the final function looks like:

/**
 * Action: Submit the form.
 *
 * @param ArrayObject $form
 *   A reference to the form array of the form for which the event
 *   was triggered.
 * @param ArrayObject $form_state
 *   A reference to the form state array of the form for which the
 *   event was triggered.
 */
function rules_forms_action_submit($form, $form_state) {
  $form_id = $form['form_id']['#value'];
  $form_state = (array)$form_state;
  drupal_form_submit($form_id, $form_state);
}


For submitting entity form, check: How to programatically submit an entityform?