Dynamic Form Fields Validation

Hi My project structure is based on Vokuro but Im using phtml instead of volt my problem is, I'm gonna have for example PersonForm.php to handle and validate regarding form.

        Person 1
            <input type="text" name="name_1">
            <input type="text" name="email_1">
            <input type="text" name="mobile_1">
        Person 2
            <input type="text" name="name_2">
            <input type="text" name="email_2">
            <input type="text" name="mobile_2"> 
        Person 3
            <input type="text" name="name_3">
            <input type="text" name="email_3">
            <input type="text" name="mobile_3"> 
        ....    

as you can see the number of person can be changged regulary so how can I validate it in Person form class PersonForm.php



67.7k

i still havent done validation with phalcon,

however why do you name your fields like this ?

    Person 1
        <input type="text" name="name[]">
        <input type="text" name="email[]">
        <input type="text" name="mobile[]">
    Person 2
        <input type="text" name="name[]">
        <input type="text" name="email[]">
        <input type="text" name="mobile[]">   
    Person 3
        <input type="text" name="name[]">
        <input type="text" name="email[]">
        <input type="text" name="mobile[]">  

and it should handle your problem i think.

some stuff are explained here: http://stackoverflow.com/questions/20184670/html-php-form-input-as-array



4.1k

thanks.. but the thing is I've got Person From Class that needs to validate this form

PersonForm.php

            $name = new Text("name");
            $name->setLabel("Name Person X");
            $name->addValidators(array(
            new PresenceOf(array(
                'message' => 'Please fill in person X name'
            ))
        ));

which X dynamically changes.

i still havent done validation with phalcon,

however why do you name your fields like this ?

  Person 1
       <input type="text" name="name[]">
       <input type="text" name="email[]">
       <input type="text" name="mobile[]">
   Person 2
       <input type="text" name="name[]">
       <input type="text" name="email[]">
       <input type="text" name="mobile[]">   
   Person 3
       <input type="text" name="name[]">
       <input type="text" name="email[]">
       <input type="text" name="mobile[]">  

and it should handle your problem i think.

some stuff are explained here: http://stackoverflow.com/questions/20184670/html-php-form-input-as-array



142

You could build a form to suit your needs?

We also need to build a dynamic form where the items it contains can be different with the same name but with different id`s.

Thanks