Closed (fixed)
Project:
AHAH helper
Version:
6.x-2.0
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Aug 2009 at 17:35 UTC
Updated:
11 Jul 2011 at 06:30 UTC
I am creating an 'add new element' button in hook_form for a module I am building that creates a new node. The button works - when I click it, new textfields are added to the page. The problem is that the submit handlers are being called when the button is being clicked. Here is the relevant code:
[code]
$form['pos_wrapper']['pos']['noun_fieldset']['counters_wrapper'] = array
(
'#prefix' => '<div id="counters_wrapper">',
'#suffix' => '</div>',
);
$form['pos_wrapper']['pos']['noun_fieldset']['counters_wrapper']['counters_count'] = array
(
'#type' => 'value',
'#value' => (isset($form_state['values']['counters_add_more'])) ? $form_state['values']['counters_count'] + 1 : 1,
);
for($i = 0; $i < $form_state['values']['counters_count'] + 1; $i++)
{
$form['pos_wrapper']['pos']['noun_fieldset']['counters_wrapper']['counters'][$i] = array
(
'#type' => 'textfield',
'#title' => t('Counters'),
'#default_value' => (isset($form_state['values']['plural_form'])) ? $form_state['values']['plural_form'] : FALSE,
);
}
$form['pos_wrapper']['pos']['noun_fieldset']['counters_add_more'] = array
(
'#type' => 'submit',
'#value' => t('Add another counter'),
'#submit' => array('ahah_helper_generic_submit'),
'#ahah' => array
(
'path' => ahah_helper_path(array('pos_wrapper', 'pos', 'noun_fieldset', 'counters_wrapper')),
'wrapper' => 'counters_wrapper',
'method' => 'replace',
'effect' => 'fade',
)
);
[/code]
If it matters, all the above code is not present when the form is initially rendered, and is added through an AHAH call itself.
I am also calling this code in hook_form_alter()
[code]
ahah_helper_register($form, $form_state);
$form['changed']['#default_value'] = $_SERVER['REQUEST_TIME'];
[/code]
So the problem isn't arising from the lack of that code.
I appreciate any help. Help!
Comments
Comment #1
jaypanI should add there are the errors I'm getting when I click the 'add more' button:
Comment #2
jaypanFortunately I've come up with a solution on my own, as I have found with this and previous inquiries that the module maintainer isn't the most forthcoming with assistance.
I ended up using the Skip Validation module, which allows validation to be skipped on a particular submit button, which I applied to the 'add more' button.
I also discovered that the bootstrap errors that were coming up were as a result of my own mistake in coding, not a result of validation.
Comment #3
Rok Žlender commented