Hi. I created a module with a node type (let’s call it "game_tip"). This node type has to be with 2 fields (in addition to default "title" and "body"). The first is the "game" and the second is the "trophy". I defined them into mymodule_form() as follows:
$form['tip_options']['game'] = array (
'#type' => 'select',
'#title' => t('Game'),
'#weight' => -4,
'#options' => (array)mm_get_gamelist(),
'#suffix' => "<div class='clear'></div>",
'#ahah' => array(
'path' => 'mymodule/js/trophylist',
'wrapper' => 'edit-trophy-wrapper',
'method' => 'replace',
'event' => 'change',
),
);
$list = mm_get_trophylist((int)$form_state['values']['game']);
$form['tip_options']['trophy'] = array (
'#type' => 'select',
'#title' => t('Game trophy'),
'#weight' => -3,
'#disabled' => $list == FALSE,
'#options' =>$list ? $list : array(0 => t('Select game first')),
);
As you can see these two fields are required. Just like "body" and "title" fields by the way =)
As written here and here I created my own callback function:
function mymodule_trophylist_js() {
include_once 'modules/node/node.pages.inc';
$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;
$form_state = array('storage' => NULL, 'rebuild' => TRUE, "force_validate" => TRUE);
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
$choice_form = $form['tip_options']['trophy'];
unset($choice_form['#prefix'], $choice_form['#suffix']);
$output = theme('status_messages') . drupal_render($choice_form);
drupal_json(array('status' => TRUE, 'data' => $output));
}
The idea of what I need is when I select the game, the callback function shall return a trophy list for this game. Everything works fine, but when I select the game the callback function does not work properly it returns me an error message with the following text:
Title field must have a value.
Body field must have a value.
and all other error messages that mymodule_validate() function generate.
Can I use AHAH there? And if 'yes' where am I wrong?
Comments
Comment #1
tbazadaykin commentedOh, i forgot "#required" in field definitions, sorry =)