Question

I write code for a site that uses Zend 1. I want to rewrite the old admin interface in zend, but my form fails to validate.

I'll post the form, the validation code and the debug output here.

Form:

class Form_Admin_Address_Neu extends Zend_Form {

public function init() {
$this->setMethod('post');

$this->addElement('text', '_street', array(
    'label' => 'Strasse:',
    'size' => 60,
    'required' => true,
    'filters' => array('StringTrim'),
));

$this->addElement('text', '_zip', array(
    'label' => 'PLZ:',
    'size' => 6,
    'required' => true,
    'filters' => array('StringTrim'),
));

$this->addElement('text', '_city', array(
    'label' => 'Stadt:',
    'required' => true,
    'size' => 30,
    'filters' => array('StringTrim'),
));

$this->addElement('text', '_lat', array(
    'label' => 'Latitude:',
    'required' => true,
    'size' => 30,
    'validators' => array('Float'),
    'filters' => array('Stringtrim'),
));

$this->addElement('text', '_lng', array(
    'label' => 'Longitude:',
    'required' => true,
    'size' => 30,
    'validators' => array('Float'),
    'filters' => array('Stringtrim'),
));

$this->addElement('checkbox', '_hidden', array(
    'label' => 'Hidden:',
    'size' => 1,
    'filters' => array('Int', 'Null'),
));

$this->addElement('submit', 'submit', array(
    'ignore' => true,
    'label' => 'Senden',
));

$this->addElement('hash', 'csrf', array(
    'ignore' => true,
));

$this->setAction('/admin/address/list');
}

}

additional fields (i just post 1 here, 2nd is like it):

class Form_Admin_Elements_CountrySelect extends Zend_Form_Element_Select {
public function init() {
$countrymapper = new Mapper_Country();
    $this->addMultiOption(0, 'Please select...');
    foreach ($countrymapper->fetchAll() as $country) {
        $this->addMultiOption($country->getId(), $country->getName());
    }
$this->setLabel("Land:");
}
}

Code:

$addForm = new Form_Admin_Address_Neu();
$regionselect = new Form_Admin_Elements_RegionSelect('region_id');
$regionselect->setRequired(true);
$addForm->addElement($regionselect);
$countryselect = new Form_Admin_Elements_CountrySelect('country_id');
$countryselect->setRequired(true);
$addForm->addElement($countryselect);

if ($addForm->isValid($_POST)) {
...
} else {
print_r($_POST);
print_r($addForm->getErrorMessages());
print_r($addForm->getCustomMessages());
print_r($addForm->getErrors());
}

output:

Array
(
[_street] => sdvdsvsv
[_zip] => 111111
[_city] => sdfgsf
[_lat] => 1.0
[_lng] => 2.1
[_hidden] => 0
[country_id] => 1
[region_id] => 3
[submit] => Senden
[csrf] => d18dfed9d26e28d7a52aa4983b00667e
)
Array
(
)
Array
(
)
Array
(
[_street] => Array
    (
    )

[_zip] => Array
    (
    )

[_city] => Array
    (
    )

[_lat] => Array
    (
        [0] => notFloat
    )

[_lng] => Array
    (
        [0] => notFloat
    )

[_hidden] => Array
    (
    )

[submit] => Array
    (
    )

[csrf] => Array
    (
    )

[region_id] => Array
    (
    )

[country_id] => Array
    (
    )

)

As I see it, the validation fails, but i dont know why. The values are present in the $_POST, but the form doesnt validate. i even tried with isValidPartial(), but same result. I think i'm doing something fundamentally wrong. A hint would be great.

ty in advance

Was it helpful?

Solution

Try to enter a comma instead of a point in Latitude and Longitude.
1,0 and 2,1 instead of 1.0 and 2.1

I think it's a problem about Locale of your validator

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top