I have some custom js code which should be executed after successful webform's submission.

JS Code :


below approaches, I already tried


$commands = array();
$commands[] = ajax_command_invoke(NULL, 'form_submit_telium');
$page = array('#type' => 'ajax', '#commands' => $commands);

-> It's not working, due to my webform is not submitted through ajax call.

$form['#attached']['js'] = array(
                drupal_get_path('module', 'module_name') . '/js/form_submit.js',


      form_submit_telium(); });",'inline');

Webform alter code:

function module_form_alter(&$form, &$form_state, $form_id){
    $form['#submit'][] = 'telium_form_submit';

function telium_form_submit(&$form, &$form_state){
    // above three approaches

Please let me know if you have any other approach to do the same thing.


Your 2nd option will work in that :


function hook_form_alter(&$form, &$form_state, $form_id){
    if($form_id == "webform_client_form_id"){
        $form['#attached']['js'][] = drupal_get_path('module', 'c1') . '/c1.js';

Js Code:

    jQuery( "#webform-client-form-id" ).submit(function( event ) {
      alert( "Handler for .submit() called." );
  • Thanks for your reply. as I mention javascript should be execute only when a form is submitted without any error. but it is also executed when form has a custom validation error. – Harshit Thakore Sep 2 at 5:38
  • also, notice that whenever the form is submitted it is redirecting to same page(both cases 1. with error and 2. without error). – Harshit Thakore Sep 2 at 5:40
  • 1.) Javascript should be call for all webforms function module_form_alter(&$form, &$form_state, $form_id) { if($form_id){ $form['#submit'][] = 'module_form_submit_handler'; // call custom submit handler function } } – Harshit Thakore Sep 2 at 6:27
  • 2.) function module_form_submit_handler(&$form, &$form_state) { $form['#attached']['js'][] = drupal_get_path('module', 'module_name') . '/js/form_submit.js'; } – Harshit Thakore Sep 2 at 6:28

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.