Drupal AHAH Callback Problem
Hello,
Please Help Me. I have searched every forum and google for 2 days now and posted this problem in numerous places with not a single suggestion. I am desparate to solve this problem and I believe it is something simple I am overlooking as I am very new to Drupal. I have a form with an AHAH callback and pagination through pager_query. The Form and pagination works perfect and displays results from my query function with pages under my Form in the DIV tag where I expect. My problem is when I click any page (Take Page 3 in my example), it calls the same callback, like I assume it should, that I used to submit the form in the first place, but I get a blank page that just displays the following single line:
{ "status": true, "data": "Hello Drupal World" }
(It only displays this for page 3 for debugging purposes, as if I showed all the results the data string would be far to long to display and I also wanted to eliminate the idea that it was a formatting issue with the original string.)
This should display "Hello Drupal World" under my form in the DIV tag that the original results from my submit button wrote to, under my form.
Here is my callback function that gets called from the submit button and from the page links at bottom:
<?php
function simple_search_callback() {
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
$form['#programmed'] = $form['#redirect'] = FALSE;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
if($page == 3) {
$op = 'Hello Drupal World'; //THIS IS JUST FOR TESTING PURPOSES
} else
$op = getSearchResults($form_state);
drupal_json(array('status' => TRUE, 'data' => $op));
}
?>
Here is the submit part of my form (This works fine):
<?php
function simple_search_my_form($form_state) {
....
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'go',
'#ahah' => array(
'path' => 'simple_search/callback',
'wrapper' => 'search-results-wrapper',
'method' => 'replace',
'effect' => 'fade',
'progress' => array('type' => 'bar', 'message' => t('Searching...')),
),
);
....
?>
JeevesBond posted this at 01:52 — 19th August 2009.
He has: 3,956 posts
Joined: Jun 2002
Sorry this hasn't received any replies, I looked at this a while ago, and couldn't think of an answer to your problem. I still can't, but can tell you what the source of the problem is.
The pager is not AHAH-ified. It is just taking the path of the AHAH callback and adding ?page=3 on the end, so the browser is sent to
simple_search/callback/?page=3
At least I think that's what is causing it. Post again to let us know if you're still struggling with this (and anyone finding this via a search is welcome to post too).
Welcome to TWF by the way!
a Padded Cell our articles site!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.