Hi guys!
I would like to ask for your help to solve a problem that is literally driving me nuts!
The idea is very simple:
Given a form1 (that includes a label1 and button1)
- clicking button1 it swaps form1 with form2 (that includes a label2 and button2);
- clicking button2 it swaps it back to form1;
- use ajax to avoid page reloading
I tried several approaches but so far I collected any result. The main issue seems that the form2 once replaces form1 has no ajax abilitated thus leading to a page reload once button2 is clicked.
Let me show u the code:
function item_fields($form, &$form_state)
{
$form['name'] = array(
'#type' => 'item',
'#title'=> $ghost_name,
'#prefix' => '
',
);
$form['action'] = array(
'#type' => 'button',
'#value'=> 'Edit',
'#executes_submit_callback' => FALSE,
'#suffix' => '
',
'#ajax' => array(
'callback' => 'item_to_edit',
'wrapper' => 'item_fields',
),
);
return $form;
}
function item_to_edit($form, $form_state)
{
return drupal_get_form('edit_fields');
}
function edit_fields($form, $form_state)
{
$form['name'] = array(
'#type' => 'textfield',
'#default_value'=> $ghost_name,
'#prefix' => '
',
);
$form['action'] = array(
'#type' => 'button',
'#value'=> 'save',