Okay, I've been at this all day but no joy. I have seen the question asked several times but no answers. When I click the submit button I get a 403 error message.
It's my understanding that the path ('a_module/js/%') should trigger the function ('a_module_search_js'). Instead I get the 403 error.
/* hook_menu */ function a_module_menu() { $items = array(); $items['admin/settings/a_module'] = array( 'title' => 'AModule', 'description' => 'Provides the configuration options for how AModule operates on the site.', 'page callback' => 'drupal_get_form', 'page arguments' => array('a_module_admin_settings'), 'access arguments' => array('administer a_module'), 'file' => 'a_module.admin.inc', );
$items['a_module/js/%'] = array( 'page callback' => 'a_module_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
return $items; }
/* the submit button from a form */ $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), '#submit' => array('a_module_a_module_submit_handler'), '#ahah' => array( 'path' => 'a_module/js/0', 'wrapper' => 'div_id', 'method' => 'replace', 'effect' => 'fade', ),
Scott wrote:
$items['a_module/js/%'] = array( 'page callback' => 'a_module_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
You need to supply the access callback and/or access arguments. You could simply add 'access callback' => TRUE if you want everyone accessing it all the time.
I've modified the code thus:
$items['a_module/js/%'] = array( 'access callback' => TRUE, 'access arguments' => array(1), 'page callback' => 'a_module_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
but it still reports a 403 error.
On Wed, 2010-05-12 at 10:41 -0400, Earnie Boyd wrote:
Scott wrote:
$items['a_module/js/%'] = array( 'page callback' => 'a_module_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
You need to supply the access callback and/or access arguments. You could simply add 'access callback' => TRUE if you want everyone accessing it all the time.
-- Earnie -- http://progw.com -- http://www.for-my-kids.com
Did you clear the cache after doing so? I don't think you need the 'access arguments' entry...
You might reference this for a better example, that honors the access content permissions setting.
http://api.drupal.org/api/function/hook_menu/6
Also remember to clear your cache before testing.
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Scott Sent: Wednesday, May 12, 2010 8:47 AM To: support@drupal.org Subject: Re: [support] AHAH 403 error
I've modified the code thus:
$items['a_module/js/%'] = array( 'access callback' => TRUE, 'access arguments' => array(1), 'page callback' => 'a_module_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
but it still reports a 403 error.
On Wed, 2010-05-12 at 10:41 -0400, Earnie Boyd wrote:
Scott wrote:
$items['a_module/js/%'] = array( 'page callback' => 'a_module_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
You need to supply the access callback and/or access arguments. You could simply add 'access callback' => TRUE if you want everyone accessing it all the time.
-- Earnie -- http://progw.com -- http://www.for-my-kids.com
-- [ Drupal support list | http://lists.drupal.org/ ]
I suppose I'm making some progress with this as now I just get a generic javascript error message that an error has occurred, no number or anything specific. My hook_menu item looks like this:
$items['citygrid/js/%'] = array( 'title' => 'CityGrid Search', 'title callback' => FALSE, 'access callback' => TRUE, 'access arguments' => array('access callback'), 'page callback' => 'citygrid_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
The page callback function looks like this:
function citygrid_search_js($delta=0) { drupal_set_message("Hello World..."); }
To let a cat out of the bag, this is a module for retrieving search results using CitySearch's new API. The configuration functions all work and the form for collecting search criteria work. It even produces the url for fetching xml or json. What I can't seem to do is get the submit button to work correctly.
On Wed, 2010-05-12 at 08:59 -0700, Metzler, David wrote:
Did you clear the cache after doing so? I don't think you need the 'access arguments' entry...
You might reference this for a better example, that honors the access content permissions setting.
http://api.drupal.org/api/function/hook_menu/6
Also remember to clear your cache before testing.
Scott wrote:
'title' => 'CityGrid Search', 'title callback' => FALSE, 'access callback' => TRUE, 'access arguments' => array('access callback'),
As David Metzler already said, 'access arguments' are not used for 'access callback' => TRUE. You also need to remove the 'title callback' => FALSE as well.
On Wed, 2010-05-12 at 08:59 -0700, Metzler, David wrote:
Did you clear the cache after doing so? I don't think you need the 'access arguments' entry...
This is probably way off, but it cost me hours on a similar feeling issue. My AJAX was failing because of an unintended redirect. This caused the AJAX to fail giving a blank return value.
My cause of the redirect was https to http forwarding that can happen with the Secure Site module (a setting that forces http forwarding for pages that are marked to not be shown in https). I added a new exception, which stopped the https -> http forwarding, and it was all fixed.
Just a thought.
Greg
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Scott Sent: Wednesday, May 12, 2010 1:49 PM To: support@drupal.org Subject: Re: [support] AHAH 403 error
I suppose I'm making some progress with this as now I just get a generic javascript error message that an error has occurred, no number or anything specific. My hook_menu item looks like this:
$items['citygrid/js/%'] = array( 'title' => 'CityGrid Search', 'title callback' => FALSE, 'access callback' => TRUE, 'access arguments' => array('access callback'), 'page callback' => 'citygrid_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
The page callback function looks like this:
function citygrid_search_js($delta=0) { drupal_set_message("Hello World..."); }
To let a cat out of the bag, this is a module for retrieving search results using CitySearch's new API. The configuration functions all work and the form for collecting search criteria work. It even produces the url for fetching xml or json. What I can't seem to do is get the submit button to work correctly.
On Wed, 2010-05-12 at 08:59 -0700, Metzler, David wrote:
Did you clear the cache after doing so? I don't think you need the 'access arguments' entry...
You might reference this for a better example, that honors the access content permissions setting.
http://api.drupal.org/api/function/hook_menu/6
Also remember to clear your cache before testing.
You should remove the access_arguments, as they aren't used, but that's not your problem.
Not sure why you have 'title callback'. Did you make that up? I think it should be removed, but again not your problem.
The page callback function should print data, not use set message if you want the data to get back to the javascript call.
function citygrid_search_js($delta = 0) { print "Hello world"; }
But of course you really should be printing the json object if I understand ahah correctly.
Dave -----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Scott Sent: Wednesday, May 12, 2010 1:49 PM To: support@drupal.org Subject: Re: [support] AHAH 403 error
I suppose I'm making some progress with this as now I just get a generic javascript error message that an error has occurred, no number or anything specific. My hook_menu item looks like this:
$items['citygrid/js/%'] = array( 'title' => 'CityGrid Search', 'title callback' => FALSE, 'access callback' => TRUE, 'access arguments' => array('access callback'), 'page callback' => 'citygrid_search_js', 'page arguments' => array(2), 'type' => MENU_CALLBACK, );
The page callback function looks like this:
function citygrid_search_js($delta=0) { drupal_set_message("Hello World..."); }
To let a cat out of the bag, this is a module for retrieving search results using CitySearch's new API. The configuration functions all work and the form for collecting search criteria work. It even produces the url for fetching xml or json. What I can't seem to do is get the submit button to work correctly.
On Wed, 2010-05-12 at 08:59 -0700, Metzler, David wrote:
Did you clear the cache after doing so? I don't think you need the 'access arguments' entry...
You might reference this for a better example, that honors the access content permissions setting.
http://api.drupal.org/api/function/hook_menu/6
Also remember to clear your cache before testing.
-- [ Drupal support list | http://lists.drupal.org/ ]
Metzler, David wrote:
You should remove the access_arguments, as they aren't used, but that's not your problem.
I haven't tested it but passing arguments to a non function could cause an issue.
Not sure why you have 'title callback'. Did you make that up? I think it should be removed, but again not your problem.
Not made up, see the user module for an example of use. It is how the user name is displayed on the user page/block. And a 'title callback' of FALSE could again be an issue but maybe not.
Thanks, hadn't seen that before.
I stand corrected.
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Earnie Boyd Sent: Wednesday, May 12, 2010 4:40 PM To: support@drupal.org Subject: Re: [support] AHAH 403 error
Metzler, David wrote:
You should remove the access_arguments, as they aren't used, but that's not your problem.
I haven't tested it but passing arguments to a non function could cause an issue.
Not sure why you have 'title callback'. Did you make that up? I think it should be removed, but again not your problem.
Not made up, see the user module for an example of use. It is how the user name is displayed on the user page/block. And a 'title callback' of FALSE could again be an issue but maybe not.
-- Earnie -- http://progw.com -- http://www.for-my-kids.com -- [ Drupal support list | http://lists.drupal.org/ ]
On Thu, 13 May 2010, Scott wrote:
What I can't seem to do is get the submit button to work correctly.
can you post the snippets of FORMS API code where you generate the button, the generated html containing the button, and possibly the javascript code that is supposed to be called?
Assume you're testing with firefox web developer plugin and looking at the error console? Explorer seems to always want to debug from a certain line number too.
Quite honestly it would seem I just don't know enough about drupal development or jQuery yet. I've generally been able to figure out how to do things by studying existing code that seems to do what I'm after. In this case I haven't found (or probably just not recognized) examples of what I wish to do. I'd be happy to package up my module as it stands and send it to anyone interested. I don't have a javascript function yet as I don't know enough about how to use jQuery. I have a form with fields for "what to look for" and "where to look for it" as well has hidden value fields for publisher_id and api_key. If I don't use the #ahah attribute but use the submit_handler function I can get a url that can fetch the xml or json from the remote server. The url works if I clip it and enter into the address bar of the browser. The url does not work as input into drupal_http_request().
By the way, it's no longer a 403 error but only a general error. I had thought that if hook_menu got the correct argument the page callback function could contain any code, even just displaying "Hello World...".
Thanks for all the help so far...
On Thu, 2010-05-13 at 10:32 +1000, Doug wrote:
On Thu, 13 May 2010, Scott wrote:
What I can't seem to do is get the submit button to work correctly.
can you post the snippets of FORMS API code where you generate the button, the generated html containing the button, and possibly the javascript code that is supposed to be called?
Assume you're testing with firefox web developer plugin and looking at the error console? Explorer seems to always want to debug from a certain line number too.
Just re-reading through the AHAH section of "Pro Drupal Development". The only AHAH attribute that comes close to actually specifying a client-side javascript function to be invoked is "method", which must take a value of iether "append", "before","prepend" or "replace" and then the javascript jquery itself is (from misc/ahah.js)
if (this.method == 'replace') { wrapper.empty().append(new_content); } else { wrapper[this.method](new_content); }
I looked at this once before and decided that AHAH seemed to be only useful for animating form elements themselves, or modifying the "wrapper" around the form element (but its quite possible I was wrong about that - maybe there is a black-art to generating special "new_content" JSON in your MENU_CALLBACK?).
My AJAX use case was for for getting events and injecting them into a javascript (jquery) calendar (not drupal related) embedded in a drupal menu "page callback". I ignored AHAH altogether and just used jquery's AJAX function directly - activated by an onclick attribute attached to a handrolled button (to avoid the every-button-is-submit bug).
Cheers Doug
On Thu, 13 May 2010, Scott wrote:
Quite honestly it would seem I just don't know enough about drupal development or jQuery yet. I've generally been able to figure out how to do things by studying existing code that seems to do what I'm after. In this case I haven't found (or probably just not recognized) examples of what I wish to do. I'd be happy to package up my module as it stands and send it to anyone interested. I don't have a javascript function yet as I don't know enough about how to use jQuery. I have a form with fields for "what to look for" and "where to look for it" as well has hidden value fields for publisher_id and api_key. If I don't use the #ahah attribute but use the submit_handler function I can get a url that can fetch the xml or json from the remote server. The url works if I clip it and enter into the address bar of the browser. The url does not work as input into drupal_http_request().
By the way, it's no longer a 403 error but only a general error. I had thought that if hook_menu got the correct argument the page callback function could contain any code, even just displaying "Hello World...".
Thanks for all the help so far...
On Thu, 2010-05-13 at 10:32 +1000, Doug wrote:
On Thu, 13 May 2010, Scott wrote:
What I can't seem to do is get the submit button to work correctly.
can you post the snippets of FORMS API code where you generate the button, the generated html containing the button, and possibly the javascript code that is supposed to be called?
Assume you're testing with firefox web developer plugin and looking at the error console? Explorer seems to always want to debug from a certain line number too.