1

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.

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

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

                    //this comes back as undefined =/
            console.log(final_redirect);

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

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

3
  • 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

3

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 that you have read and understand our privacy policy and code of conduct.

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