【发布时间】:2011-04-05 10:56:24
【问题描述】:
你好,我有一个表单,用户可以点击一个按钮并动态添加新元素(使用 Jquery)
<input name="sconto[]" type="text"><br>
<input name="sconto[]" type="text"><br>
<input name="sconto[]" type="text"><br>
...
我有一个浮点数的自定义验证器,格式为逗号和点分隔,如 20.50 和 20,50 问题是我似乎无法找到如何让 zend 将其应用于数组的每个元素。
那么我应该如何声明这个元素以及如何应用验证器? xD
这是我的验证器
protected $_messageTemplates = array(
self::NON_E_NUMERO => 'non sembra essere un numero'
);
public function isValid($value, $context = null)
{
$pos_virgola = strpos($value, ",");
if ($pos_virgola !== false)
$value = str_replace(",", ".", $value);
if (!is_numeric($value))
{
$this->_error(self::NON_E_NUMERO, $value);
return false;
}
else
return true;
}
}
我不知道怎么做的表格,我用这个但显然它不起作用
$sconto = $this->createElement('text','sconto')->setLabel('sconto');
//->setValidators(array(new Gestionale_Validator_Float()));
$this->addElement($sconto);
...
$sconto->setDecorators(array(//no ViewHelper
'Errors',
'Description',
array(array('data' => 'HtmlTag'), array('tag' => 'td', /*'class' => 'valore_campo', */'id'=>'sconto')),
array('TdLabel', array('placement' => 'prepend', 'class' => 'nome_campo'))
));
【问题讨论】:
-
您能否提供表单和验证器的代码。
-
我可以用 sconto[0] sconto[1] ... 用 javascript,问题是我不知道用户会输入多少
-
是的,这些就是我更喜欢自己处理表单和 $_POST 数据的原因。我只是希望 Zend_Form 能够在版本 2 中不辜负 Zend Framework 的其余部分。
标签: zend-framework forms