Created
March 17, 2017 19:40
-
-
Save iefrati/41ca4078e0c07617feccbfcad701d429 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cals_webforms_exit($destination = NULL) { | |
if (arg(0) == 'system' && arg(1) == 'ajax') { | |
$is_user_webform_submission = isset($_POST) && isset($_POST['form_build_id']) && isset($_POST['form_token']); | |
if ($is_user_webform_submission && user_is_anonymous()) { | |
$form_build_id = $_POST['form_build_id']; | |
$form_id = $_POST['form_id']; | |
$form_state = form_state_defaults(); | |
$form_state['values'] = $_POST; // Important! | |
$form = form_get_cache($form_build_id, $form_state); | |
if (!$form) { | |
watchdog(__FUNCTION__, 'AJAX form submission failed. Trying again...', array(), WATCHDOG_WARNING); | |
$form = drupal_rebuild_form($form_id, $form_state); | |
$form['#build_id_old'] = $form['#build_id']; // Important! | |
// Try form submission again after it is rebuilt above | |
$commands[] = ajax_command_update_build_id($form); | |
$commands[] = ajax_command_invoke('form', 'click', array('submit')); | |
print ajax_render($commands); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment