Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
Zend framework2 Zend框架$form->;isValid($formData)返回invalid,我不知道为什么_Zend Framework2_Zend Form - Fatal编程技术网

Zend framework2 Zend框架$form->;isValid($formData)返回invalid,我不知道为什么

Zend framework2 Zend框架$form->;isValid($formData)返回invalid,我不知道为什么,zend-framework2,zend-form,Zend Framework2,Zend Form,我有一个2步表单(花哨的名称),但是,当我提交此表单时,验证始终返回false,我调试了它并收到了我想要的所有参数,但是出于某种原因,isValid为false,并且在RadioButton元素中出现了一些错误,代码如下: 这是forms/Users.php public function signup() { $contryModel = new Application_Model_Country(); $countries = $contryM

我有一个2步表单(花哨的名称),但是,当我提交此表单时,验证始终返回false,我调试了它并收到了我想要的所有参数,但是出于某种原因,isValid为false,并且在RadioButton元素中出现了一些错误,代码如下:

这是forms/Users.php

public function signup()
    {   

        $contryModel = new Application_Model_Country();
        $countries = $contryModel->getCountries();
        foreach ($countries as $array)
        {
            if(isset($array['id_country'])){
                $countryArr[$array['id_country']] = $array['country']; 
            }
        } 

        array_unshift($countryArr, '-- Select Your Country --');

        $name = new Zend_Form_Element_Text('Name');
        $name->setLabel('Name')
                ->setRequired(true)
                ->addValidator('NotEmpty');

        $lastname = new Zend_Form_Element_Text('LastName');
        $lastname->setLabel('Last Name')
                    ->setRequired(true)
                    ->addValidator('NotEmpty');

        $email = new Zend_Form_Element_Text('Email');
        $email->setLabel('Email')
                ->setRequired(true)
                ->addValidator('NotEmpty');

        $website = new Zend_Form_Element_Text('Website');
        $website->setLabel('Website')
                ->setRequired(true)
                ->addValidator('NotEmpty');

        $country = new Zend_Form_Element_Select('Country');
        $country->setLabel('Country')
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->addMultiOptions($countryArr);

        $city = new Zend_Form_Element_Select('City');
        $city->setLabel('City')
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->addMultiOptions(array('-- Select Your City --'))
                ->setRegisterInArrayValidator(false)
                ->setAttrib('disabled',true);


        $password = new Zend_Form_Element_Password('Password');
        $password->setLabel('Password')
                ->setRequired(true)
                ->addValidator('NotEmpty');

        $rpassword = new Zend_Form_Element_Password('RepeatPassword');
        $rpassword->setLabel('Repeat Password')
                ->setRequired(true)
                ->addValidator('NotEmpty');

        $why = new Zend_Form_Element_Textarea('Why');
        $why->setRequired(true)
            ->addValidator('NotEmpty')
            ->setAttrib('cols', '50')
            ->setAttrib('rows', '4');

        $job = new Zend_Form_Element_Text('Job');
        $job->setLabel("Job")
            ->setRequired(true)
            ->addValidator('NotEmpty');


        $boxes = new Application_Model_Colors();
        $res = $boxes->getColors();

        foreach($res as $colors){
            $colorArr[$colors['id']]['color'] = $colors['color'];
            $colorArr[$colors['id']]['overColor'] = $colors['overColor'];

        }

        $color = new Zend_Form_Element_Radio('color');
        $color->setLabel('Color')
                ->addMultiOptions($colorArr)
                ->addValidator('NotEmpty');



        $save = new Zend_Form_Element_Submit('Submit');
        $save->setLabel('Save');


        $this->addElements(array($name, $lastname, $email, $website, $password, $rpassword, $job, $country, $city, $color, $why, $save));

    }
*这是视图*的一部分,我在其中格式化收音机

<?php
foreach($this->form->color->options as $key=>$colors){

            echo "<label><input type='radio' value='$key' name='color'><div class='registrationBoxes' style='background-color:#".$colors['color']."' data-color='".$colors['color']."' data-overColor='".$colors['overColor']."'  value='".$colors['color']."'></div></label>";

}
?> 
模具(var_dump())返回以下内容:

array(12) {
  ["Name"]=>
  string(9) "Some name"
  ["LastName"]=>
  string(13) "Some lastName"
  ["Email"]=>
  string(21) "Someemail@hotmail.com"
  ["Password"]=>
  string(5) "Some "
  ["RepeatPassword"]=>
  string(5) "Some "
  ["Website"]=>
  string(12) "Some website"
  ["Job"]=>
  string(8) "Some job"
  ["Country"]=>
  string(1) "7"
  ["City"]=>
  string(3) "434"
  ["color"]=>
  string(1) "3"
  ["Why"]=>
  string(10) "Emotional!"
  ["Submit"]=>
  string(4) "Save"
}
正如你所看到的,所有的参数都带有值,但是没有任何理由isValid返回false,一些有想法的家伙

谢谢-

编辑

这是Tonunu所需的Zend/form.php代码的一部分

public function __construct ($options = null)
{
    if (is_array($options)) {
        $this->setOptions($options);
    } elseif ($options instanceof Zend_Config) {
        $this->setConfig($options);
    }
    // Extensions...
    $this->init();
    $this->loadDefaultDecorators();
}



public function __clone ()
{
    $elements = array();
    foreach ($this->getElements() as $name => $element) {
        $elements[] = clone $element;
    }
    $this->setElements($elements);
    $subForms = array();
    foreach ($this->getSubForms() as $name => $subForm) {
        $subForms[$name] = clone $subForm;
    }
    $this->setSubForms($subForms);
    $displayGroups = array();
    foreach ($this->_displayGroups as $group) {
        $clone = clone $group;
        $elements = array();
        foreach ($clone->getElements() as $name => $e) {
            $elements[] = $this->getElement($name);
        }
        $clone->setElements($elements);
        $displayGroups[] = $clone;
    }
    $this->setDisplayGroups($displayGroups);
}

public function setOptions (array $options)
{
    if (isset($options['prefixPath'])) {
        $this->addPrefixPaths($options['prefixPath']);
        unset($options['prefixPath']);
    }
    if (isset($options['elementPrefixPath'])) {
        $this->addElementPrefixPaths($options['elementPrefixPath']);
        unset($options['elementPrefixPath']);
    }
    if (isset($options['displayGroupPrefixPath'])) {
        $this->addDisplayGroupPrefixPaths(
        $options['displayGroupPrefixPath']);
        unset($options['displayGroupPrefixPath']);
    }
    if (isset($options['elementDecorators'])) {
        $this->_elementDecorators = $options['elementDecorators'];
        unset($options['elementDecorators']);
    }
    if (isset($options['elements'])) {
        $this->setElements($options['elements']);
        unset($options['elements']);
    }
    if (isset($options['defaultDisplayGroupClass'])) {
        $this->setDefaultDisplayGroupClass(
        $options['defaultDisplayGroupClass']);
        unset($options['defaultDisplayGroupClass']);
    }
    if (isset($options['displayGroupDecorators'])) {
        $displayGroupDecorators = $options['displayGroupDecorators'];
        unset($options['displayGroupDecorators']);
    }
    if (isset($options['elementsBelongTo'])) {
        $elementsBelongTo = $options['elementsBelongTo'];
        unset($options['elementsBelongTo']);
    }
    if (isset($options['attribs'])) {
        $this->addAttribs($options['attribs']);
        unset($options['attribs']);
    }
    $forbidden = array('Options', 'Config', 'PluginLoader', 'SubForms', 
    'View', 'Translator', 'Attrib', 'Default');
    foreach ($options as $key => $value) {
        $normalized = ucfirst($key);
        if (in_array($normalized, $forbidden)) {
            continue;
        }
        $method = 'set' . $normalized;
        if (method_exists($this, $method)) {
            $this->$method($value);
        } else {
            $this->setAttrib($key, $value);
        }
    }
    if (isset($displayGroupDecorators)) {
        $this->setDisplayGroupDecorators($displayGroupDecorators);
    }
    if (isset($elementsBelongTo)) {
        $this->setElementsBelongTo($elementsBelongTo);
    }
    return $this;
}

为了检查您的表单是否有效,您必须使用此方法将数据放入表单中

$form->setData($formData)
然后你可以要求验证

$form->isValid()
因此,您需要的是:

$formData = $this->getRequest()->getPost();
$form->setData($formData);
if($form->isValid()){
  //Blablablabla
}

消息:方法setData不存在,请单击Andres。我建议你阅读并浏览一下你在这里可以找到的专辑教程:你可以根据自己的需要调整“添加专辑”的内容。谢谢托努努的建议,我会的,剩下的我会回答你的。再次感谢你。
$formData = $this->getRequest()->getPost();
$form->setData($formData);
if($form->isValid()){
  //Blablablabla
}