2017-10-04 24 views
0

我正在使用ValidForm Builder在PHP中构建复杂表单。
我正在面对一些使用框架的问题......我想制作一个包含多个隐藏区域或FieldSet的向导窗体,这些区域应该有一个可点击的按钮,点击后会显示下一个区域。如何将按钮动作添加到区域

这是什么我试图做一个例子:

$profile_page = $objForm->addPage("profile_page", "Your Profile");// 1st page 

$product_area = new Area("1 - Choose your product"); // 1st Area 

// fields to be validated before showing the next Area, whene clicking on 
// the button 'Next' 
$product_name = $product_area ->addField .... 
$product_price = $product_area ->addField ....// 
$product_type = $product_area ->addField ....// 

$next_btn = new Button('Next'); // the Next button 

// throw an error if its an Area object 
$product_area ->addField($next_btn); // can't add a navigation Bouton ! 

$user_area = new Area("2 - Your Informations"); // 2nd Area 'hidden' 

$user_firstname = $user_area->addField ....// 2nd Area fields 
$user_lastname = $user_area->addField ....// 
.... 

我可以切换到字段集,但我不能添加按钮和字段集或区域对象之间的行为或条件..

所以,我怎么可以添加相关的按钮点击的情况,所以如果我点击指定的按钮,它会验证当前后显示下隐藏区域...

预先感谢您..

回答

0

如果您使用ValidWizard,则无需自行添加下一个以前的按钮和操作。 ValidWizard为你照顾。

您确实需要将validwizard.js文件添加到您的代码中。

感谢您的问题,我发现页面导航有问题,并在GitHub上提出了拉取请求。一旦它被添加到基本代码,页面导航将按预期工作。

一个非常基本的设置是:

$objForm = new ValidWizard(
    "awesomeWizard", 
    "Please fill out my cool wizard", 
    "/stuff", 
    array(
     "nextLabel" => "Next page", 
     "previousLabel" => "Previous page" 
    ) 
); 

$objForm->addPage("firstPage", "First Page"); 

$objForm->addField(
    'name', 
    'Name', 
    ValidForm::VFORM_STRING, 
    ["required" => true], 
    ["required" => "This field is required"] 
); 

$objForm->addPage("secondPage", "Second Page"); 

$objForm->addField(
    'city', 
    'City', 
    ValidForm::VFORM_STRING, 
    ["required" => true], 
    ["required" => "This field is required"] 
); 

//*** Output submitted data or the form 
if ($objForm->isSubmitted() && $objForm->isValid()) { 
    $strOutput = $objForm->valuesAsHtml(); 
} else { 
    $strOutput = $objForm->toHtml(); 
} 

echo $strOutput; 
+0

非常感谢你对你的快速回复,但主要的过程中,我想实现的是地区或领域之间的导航Wizard'Page本身内,临睡前到下一页。 – Houcine

+0

如果我理解正确,那么在进入下一个之前,您想要验证特定的部分,对不对?这就是向导功能的用途。 或者,您可以使用JavaScript钩入'validate'方法,并使用可选的选择器强制在特定区域内进行验证。 –

相关问题