为什么ValidForm Builder不能与我的addConditions一起使用?

时间:2014-01-28 19:11:05

标签: php conditional-statements validform

以下代码显示我尝试让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 - 选择固定 enter image description here

选项#2 - 选择百分比 enter image description here

选项#3 - 选择计算 enter image description here

我的试用版&错误测试:

  1. 将addCondition()语句保留在上面显示的代码块中 - 不成功
  2. 将addCondition()语句移到所有$ objGroup-> addField()元素下面 - 没有成功
  3. 尝试将每个比较值 - 'F'更改为'固定','P'更改为'百分比',将'C'更改为'计算' - 不成功
  4. 尝试使用双引号与单引号[例如,$ objCalculation-> addCondition(“visible”,true,array(new VF_Comparison($ objWeb,VFORM_COMPARISON_EQUAL,“C”)));] - 没有成功

1 个答案:

答案 0 :(得分:0)

问题在于您已将所有三个字段命名为完全相同。您应该始终在HTML表单中使用唯一的字段名称,特别是在ValidForm Builder中,因为它根据名称(ID)选择字段。

如果您有多个具有相同ID的字段,则会在所有这些字段上执行条件javascript逻辑,这正是这里发生的事情。

请告诉我这是否适合您。