By span on
Hello.
I'm trying to create an AHAH example solution for a form and I've run into a problem where I'm getting a 403 error from the AHAH callback.
Here is the specific error: An HTTP error 403 occurred. /my_module/js
And this is the code:
/**
* Implementation of hook_menu. Adds a page callback for the form
* and a menu callback for the AHAH button to work on.
*
**/
function my_module_menu() {
$items = array();
$items['admin/ahah/ahah_test'] = array(
'title' => 'AHAH test',
'description' => 'This is an AHAH test.',
'page callback' => 'drupal_get_form',
'page arguments' => array('my_module_ahah_form'),
'access arguments' => array('access content'),
);
$items['my_module/js'] = array(
'title' => 'AHAH Test callback',
'page_callback' => 'my_module_js',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Callback for the AHAH magic, defined in hook_menu as a path
* and added to the form on submit buttons AHAH property.
*
* The return HTML will be output by AHAH, needs to be JSON formatted.
*
**/
function my_module_js() {
return drupal_json(array('status' => TRUE, 'data' => "Hello Drupal World"));;
}
/**
* The actual form, defines a fieldset and a wrapper containing a field and
* a button that calls the AHAH page that is defined in hook_menu.
*
**/
function my_module_ahah_form() {
$form = array();
// A div wrapper for everything
$form['wrapper'] = array(
'#prefix' => '<div id="my-wrapper">',
'#suffix' => '</div>',
);
// A div wrapper for the JS to work on which will contain the fields
$form['wrapper']['fields'] = array(
'#prefix' => '<div id="more-fields">',
'#suffix' => '</div>',
);
// A field into the fields-wrapper for form input
$form['wrapper']['fields']['text_1'] = array(
'#type' => 'textfield',
'#title' => t('Textfield'),
);
// A button with special AHAH properties and a special submit
$form['wrapper']['add_fields'] = array(
'#type' => 'submit',
'#value' => t('Add text'),
'#description' => t("If the amount of fields above isn't enough, click here to add more fields."),
'#submit' => array('my_module_more_fields_submit'), // If no javascript action, use this.
'#ahah' => array(
'event' => 'click', // Other options, change/blur
'path' => 'my_module/js', // Path defined in hook_menu
'wrapper' => 'more-fields', // The wrapper for the AHAH content
'method' => 'after', // Replaces current content in the wrapper, options are: after/append/before/prepend
'effect' => 'fade', // The effect, could also be none/slide
'progress' => array(
'type' => 'bar', // Progress type is bar
'message' => t('Loading...'),
)
)
);
return $form;
}
I'd be very grateful for any input on this.
span
Comments
It looks right to me... but
It looks right to me... but in the function my_module_js I can see a double semicolon at the return. Maybe it causes de problem?
Thank you for your quick
Thank you for your quick response, unfortunately removing the semi-colon didn't make things better. Will keep looking for an answer.
Did you clear your cache? Go
Did you clear your cache? Go to admin/settings/performance and click "clear cache" button. Then try again...
Yep, cleared it using devel
Yep, cleared it using devel :]
What about the user
What about the user permissions?
Yeah, permissions are set ok.
Yeah, permissions are set ok. I'm logged in as user 1 so it shouldn't be an issue anyway but I doublechecked.
Gonna try a fresh install of Drupal, this is weird :P
Well, I installed your module
Well, I installed your module and that's what I can see:
If you go to the table {menu_router} in your database and you find for the row with path my_module/js, you'll see that there's no page callback stored in your database. So the path exists and hook_menu creates it, but for some reason, page callback is not stored. There exists a hook_js for administration menu and maybe the problem is your method name.
I'm gonna try it in a few minutes if you don't get it done but now I must do something else.
WTF! I didn't see it. It's
WTF! I didn't see it. It's not page_callback, it's page callback! xD
DOH! Ack! Doh! Garhgh! Thank
DOH!
Ack! Doh! Garhgh!
Thank you Dani for having eyes :P