以下代码显示我尝试让addCondition()
与PHP ValidForm Builder一起使用。唯一有效的条件是第三个条件 - 计算 - 当它出现时,所有3个条件形式元素都会出现。
ValidForm Builder可以处理多个条件吗?
// PRICEMETHOD
$objWeb = $objGroup->addField('priceMethod', 'Price Method', VFORM_RADIO_LIST,
array('required' => (($_POST['action'] == 'delete') ? false : true)),
array('required' => 'Price Method is required'),
array(
'fieldclass' => 'vf__inlineButtons',
'tip' => (($_SESSION['auth']['tips'] && $_POST['action'] != 'delete') ? VFB_TIP_SERVICES_PRICEMETHOD : NULL),
(($_POST['action'] == 'delete') ? 'fieldDisabled' : 'fieldEnabled') => (($_POST['action'] == 'delete') ? 'disabled' : 'enabled'),
'default' => $default['priceMethod']
)
);
$objWeb->addField('Fixed', 'F');
$objWeb->addField('Percent', 'P');
$objWeb->addField('Calculation', 'C');
// PRICERATE CONDITION -- FIXED
$objFixed = $objGroup->addField('priceRate', 'Price Rate', VFORM_TEXT,
array(
'required' => (($_POST['action'] == 'delete') ? false : true),
'maxLength' => VFB_MAXLENGTH_SERVICES_PRICERATE
),
array('required' => 'Price Rate is required'),
array(
'fieldclass' => 'vf__textarea255',
'tip' => (($_SESSION['auth']['tips'] && $_POST['action'] != 'delete') ? VFB_TIP_SERVICES_PRICERATE : NULL),
(($_POST['action'] == 'delete') ? 'fieldDisabled' : 'fieldEnabled') => (($_POST['action'] == 'delete') ? 'disabled' : 'enabled'),
'default' => $default['priceRate']
)
);
$objFixed->addCondition('visible', true,
array(new VF_Comparison($objWeb, VFORM_COMPARISON_EQUAL, 'F'))
);
// PRICERATE CONDITION -- PERCENT
$objPercent = $objGroup->addField('priceRate', 'Price Rate', VFORM_TEXT,
array(
'required' => (($_POST['action'] == 'delete') ? false : true),
'maxLength' => VFB_MAXLENGTH_SERVICES_PRICERATE
),
array('required' => 'Price Rate is required'),
array(
'fieldclass' => 'vf__textarea255',
'tip' => (($_SESSION['auth']['tips'] && $_POST['action'] != 'delete') ? VFB_TIP_SERVICES_PRICERATE : NULL),
(($_POST['action'] == 'delete') ? 'fieldDisabled' : 'fieldEnabled') => (($_POST['action'] == 'delete') ? 'disabled' : 'enabled'),
'default' => $default['priceRate']
)
);
$objPercent->addCondition('visible', true,
array(new VF_Comparison($objWeb, VFORM_COMPARISON_EQUAL, 'P'))
);
// PRICERATE CONDITION -- CALCULATION
$objCalculation = $objGroup->addField('priceRate', 'Price Rate', VFORM_TEXT,
array(
'required' => (($_POST['action'] == 'delete') ? false : true),
'maxLength' => VFB_MAXLENGTH_SERVICES_PRICERATE
),
array('required' => 'Price Rate is required'),
array(
'fieldclass' => 'vf__textarea255',
'tip' => (($_SESSION['auth']['tips'] && $_POST['action'] != 'delete') ? VFB_TIP_SERVICES_PRICERATE : NULL),
(($_POST['action'] == 'delete') ? 'fieldDisabled' : 'fieldEnabled') => (($_POST['action'] == 'delete') ? 'disabled' : 'enabled'),
'default' => $default['priceRate']
)
);
$objCalculation->addCondition('visible', true,
array(new VF_Comparison($objWeb, VFORM_COMPARISON_EQUAL, 'C'))
);
仅供参考 - 在这种状况下发生的事情正在发展并会发生变化。我现在需要知道和做的就是让多标准条件化,如果可能的话。
行为结果
选项#1 - 选择固定
选项#2 - 选择百分比
选项#3 - 选择计算
我的试用版&错误测试:
答案 0 :(得分:0)
问题在于您已将所有三个字段命名为完全相同。您应该始终在HTML表单中使用唯一的字段名称,特别是在ValidForm Builder中,因为它根据名称(ID)选择字段。
如果您有多个具有相同ID的字段,则会在所有这些字段上执行条件javascript逻辑,这正是这里发生的事情。
请告诉我这是否适合您。