Drupal 7: drupal_execute has Gone, Say Hello to drupal_form_submit

17th August 2011

As has been commented elsewhere, when you're programmatically inserting data the most reliable way of doing so is often to simulate form submission - that way, any validation rules are applied and other modules have a chance to intercept the submission to do what they need to with the data. This was achieved using the function drupal_execute:

$form_state = array();
$form_state['values'] = array();
$form_state['values']['field1'] = $value1;
$form_state['values']['field2'] = $value2;
drupal_execute('your_form_id', $form_state);

However,

drupal_execute has gone altogether from Drupal 7. Instead, you need simply replace any call to drupal_execute with the new function drupal_form_submit (see the documentation). Otherwise, everything (from the point of view of your syntax) remains the same. Don't forget to use form_get_errors() to ensure that the form has validated.