Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Zend表单创建动态输入名称_Php_Forms_Zend Framework_Zend Form - Fatal编程技术网

Php 使用Zend表单创建动态输入名称

Php 使用Zend表单创建动态输入名称,php,forms,zend-framework,zend-form,Php,Forms,Zend Framework,Zend Form,我想让我的Zend_Form_Element_文本动态,也就是说,它将接受不同的输入名称 我有这个: $email = new Zend_Form_Element_Text('email'); 它以“email”作为名称创建输入: <input name="email" id="email" size="20" maxlength="100" placeholder="Email" class="input" type="text"> 但有时我收到一些外部POST请求,它

我想让我的Zend_Form_Element_文本动态,也就是说,它将接受不同的输入名称

我有这个:

 $email = new Zend_Form_Element_Text('email');
它以“email”作为名称创建输入:

 <input name="email" id="email" size="20" maxlength="100" placeholder="Email" class="input" type="text">

但有时我收到一些外部POST请求,它们的输入名称字段不同,如下所示:

 <input name="login_Email" id="email" size="20" maxlength="100" placeholder="Email" class="input" type="text">


你能告诉我怎么做吗?

在你的控制器中,我想你有这样的东西来获取POST变量:

if ($this->getRequest()->isPost()) {
    $formData = $this->getRequest()->getPost();

    if ($form->isValid($formData)) {
    ....
因此,您可以测试每个POST变量,如果它比“email”匹配,而不等于“email”,您可以创建一个新的电子邮件变量POST

if ($this->getRequest()->isPost()) {
    $formData = $this->getRequest()->getPost();

    foreach($formData as $name => $value){      
        if ($name != 'email' && preg_match("/email/i", $name))
            $formData['email'] = $value;
    }
    if ($form->isValid($formData)) {
    ...

谢谢,这就是我需要的答案!