I am struggling to understand how this works and I just can not get a grasp of if it. Basically what I am trying to do is get the results from my php function and pass it into ajax to make my page redirect to a certain area.

This is what I have for my php

function paydayform_submit($form, &$form_state){

    $entry = payday_parse($form, $form_state);

    /*if($entry['response'] == "sold"){
        print 'success';
    } else {
        print 'failed';

    drupal_add_js(array('payday_form' => array('redirect'=>$entry)), 'settings');


And this is where I am completely lost and in the dark at.

Drupal.behaviors.payday_form = {
 attach: function (context, settings) {
    $('#edit-submit', context).once('payday_form', function () {

            //Response from payday_parse($form, &$form_state)
            final_redirect = Drupal.settings.payday_form.redirect;

                    //this comes back as undefined =/

            //if statement giving from the response above.
            if(final_redirect = 'success'){
                console.log('didnt work');

Am I using this correctly? What am I doing wrong that it isnt picking up the function?

  • I'm not very familiar with behaviours, but I wonder, is the behaviour supposed to be an object?
    – Letharion
    Jun 24, 2013 at 20:03
  • Why close vote on this? Passing arguments from PHP to behaviors is a legitimate Drupal question. @Letharion yes it is supposed to look about that.
    – Mołot
    Jun 25, 2013 at 7:13
  • final_redirect = Drupal.settings.payday_form.redirect; - where was that variable declared with var keyword? If nowhere then why, yes, it is undefined / undeclared.
    – Mołot
    Jun 25, 2013 at 7:15

1 Answer 1


Use ajax_command_settings. Here is the answer Drupal.settings merging when using AJAX

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.