Hi,
it's because EPESI executes your code in linear manner. It means, that your callback_href method gets called in place where create_callback_href was called.
In this situation your execution stack looks like this
body()
body() -> href clicked -> test_form1() // returns true, so every subsequent call will stick to this method
body() -> href clicked -> test_form1() -> submit test form1 -> config_table_test() // here your second form is generated, but $form_select_tables->display(); is called either
// after config_table_test submit EPESI will follow this execution path
body() -> href clicked -> test_form1() // no future calls, because test form 1 was not submitted
to make your code working you should read something about module variables.
Those variables are stored in session for particular module. You can reference them with ampersand and it will be saved on value change. There is no need to explicit save this variables.
public function body(){ // Here you will place the main code for the module.
print('<a '.$this->create_callback_href(array($this,'test_form1')).'>FORM 1</a>');
}
public function test_form1(){
for ($i = 1; $i <= 10; $i++){
$array_tables[$i]='table'.$i;
}
$selected_table = & $this->get_module_variable('form1_submitted', false);
$form_select_tables = & $this->init_module('Libs/QuickForm', null, 'first_form');
$form_select_tables->addElement('select', 'iTable', 'Selecciona',$array_tables);
$form_select_tables->addElement('submit','submit_button','Aceptar');
if ($form_select_tables->validate()) {
$values = $form_select_tables->exportValues();
$selected_table = $values[iTable];
}
if ($selected_table !== false) {
$this->config_table_test($array_tables[$selected_table]);
} else {
$form_select_tables->display();
}
return true;
}
public function config_table_test($table){
$form_config_table =$this->init_module('Libs/QuickForm', null, 'second_form');
$form_config_table->addElement('text', 'iValue1', 'Value');
$form_config_table->addElement('text', 'iDescription1', 'Description');
$form_config_table->addElement('submit','submit_button1','Insert');
if ($form_config_table->validate()) {
$values = $form_config_table->exportValues();
echo 'Table: '.$$table.' New value: '.$values['iValue'] .', New Description: '.$values['iDescription'];
}
$form_config_table->display();
}
You can add back button in the config_table_test, which will unset module variable, to come back to the first form.
Also it may be useful to submit unique name for quickform modules. However it should work in this example without them, but in case where the first form will not be generated, then the second may become first and some glitches may occur.
Regards,
Adam