0

I am running Facebook advertising campaign for my site. The below code needs to be executed when registration is completed. How can I achieve this?

<script>
// Track when a registration form is completed (ex. complete subscription, sign up for a service)
fbq('track', 'CompleteRegistration');
</script>
1

You need to add callback for the form submission. Something like this

function your_module_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#form_id'] == 'your_form_id') {
    $form['#submit'][] = 'custom_callback';
  }
}

function custom_callback() {
  drupal_set_message('This is my custom message');
}

Now, after the form submission, the custom_callback will also be executed.

If the code is Javascript and the form submission is via Ajax, you may have a look at the Ajax framework and Ajax framework commands topics in the API documentation. How to execute custom javascript code after an ajax succes (using the Drupal Ajax framework) ? is another useful page/

0

You can redirect user on specific page after registration and this js-code should be inserted on this page.

  • How can i redirect user ? – brainHax Jan 19 '16 at 13:22
  • $form_state['redirect'] = 'path'; in you submit callback. – Maria Kvitova Jan 19 '16 at 14:21

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.