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?
final_redirect = Drupal.settings.payday_form.redirect;
- where was that variable declared withvar
keyword? If nowhere then why, yes, it is undefined / undeclared.