Hallo EPESI team,
Based on above example may I suggest an update to the LeightboxPrompt module.
The form validation check and opening the Leightbox if form not valid will be done automatic within the LeightboxPrompt object.
Modifications as follows:
public function add_option($key, $label, $icon, $form=null) {
$this->options[$key] = array('icon'=>$icon, 'form'=>$form, 'label'=>$label);
//-------BEGIN NEW CODE --------//
if (isset($form) && $form->exportValue('submited') && !$form->validate()) $this->open();
//-------END NEW CODE --------//
}
public function body($header='', $params = array(), $add_disp='', $big=true) {
if (MOBILE_DEVICE) return;
if (isset($_REQUEST['__location']) && $this->last_location!=$_REQUEST['__location']) {
$this->last_location = $_REQUEST['__location'];
$this->leightbox_ready = false;
}
if (!$this->leightbox_ready) {
if (!empty($params)) {
$this->params = $params;
$js = 'f'.$this->group.'_set_params = function(arg'.implode(',arg',array_keys($params)).'){';
foreach ($params as $k=>$v) {
$js .= 'els=document.getElementsByName(\''.$this->group.'_'.$v.'\');';
$js .= 'i=0;while(i<els.length){els[i].value=arg'.$k.';i++;}';
}
$js .= '}';
eval_js($js);
}
$this->leightbox_ready = true;
eval_js_once('f'.$this->group.'_prompt_deactivate = function(){leightbox_deactivate(\''.$this->group.'_prompt_leightbox\');}');
eval_js_once('f'.$this->group.'_show_form = function(arg){$(arg+\'_'.$this->group.'_form_section\').style.display=\'block\';$(\''.$this->group.'_buttons_section\').style.display=\'none\';}');
eval_js('$(\''.$this->group.'_buttons_section\').style.display=\''.(count($this->options)==1?'none':'block').'\';');
$buttons = array();
$sections = array();
foreach ($this->options as $k=>$v) {
$next_button = array('icon'=>$v['icon'], 'label'=>$v['label']);
if ($v['form']!==null) $form = $v['form'];
else $form = $this->options[$k]['form'] = $this->init_module('Libs/QuickForm');
if (!empty($params)) {
foreach ($params as $w)
$form->addElement('hidden', $this->group.'_'.$w, 'none', array('id'=>$this->group.'_'.$w));
}
if ($v['form']!==null) {
$v['form']->addElement('button', 'cancel', __('Cancel'), array('id'=>$this->group.'_lp_cancel', 'onclick'=>count($this->options)==1?'f'.$this->group.'_prompt_deactivate();':'$(\''.$this->group.'_buttons_section\').style.display=\'block\';$(\''.$k.'_'.$this->group.'_form_section\').style.display=\'none\';'));
$v['form']->addElement('submit', 'submit', __('OK'), array('id'=>$this->group.'_lp_submit', 'onclick'=>'f'.$this->group.'_prompt_deactivate();'));
ob_start();
$th = $this->init_module('Base/Theme');
$v['form']->assign_theme('form', $th);
$th->display('form');
$form_contents = ob_get_clean();
$next_button['open'] = '<a href="javascript:void(0);" onclick="f'.$this->group.'_show_form(\''.$k.'\');">';
$sections[] = '<div id="'.$k.'_'.$this->group.'_form_section" style="display:none;">'.$form_contents.'</div>';
eval_js('$(\''.$k.'_'.$this->group.'_form_section\').style.display=\''.(count($this->options)!=1?'none':'block').'\';');
//-------BEGIN NEW CODE --------//
if ($v['form']->exportValue('submited') && !$v['form']->validate()) {
// open this selection
eval_js('f' . $this->get_group_key() ."_show_form('$k')");
}
//-------END NEW CODE --------//
} else {
// $next_button['open'] = '<a '.$this->create_callback_href(array($this,'option_chosen'), array($k)).' onmouseup="f'.$this->group.'_prompt_deactivate();">';
$next_button['open'] = '<a href="javascript:void(0);" onmouseup="f'.$this->group.'_prompt_deactivate();'.$form->get_submit_form_js().';">';
$form->display();
}
$next_button['close'] = '</a>';
$buttons[] = $next_button;
}
$theme = $this->init_module('Base/Theme');
$theme->assign('open_buttons_section','<div id="'.$this->group.'_buttons_section">');
$theme->assign('buttons',$buttons);
$theme->assign('sections',$sections);
$theme->assign('additional_info',$add_disp);
$theme->assign('close_buttons_section','</div>');
ob_start();
$theme->display('leightbox');
$profiles_out = ob_get_clean();
Libs_LeightboxCommon::display($this->group.'_prompt_leightbox', $profiles_out, $header, $big);
}
}