Thursday, May 22, 2014

RE: Validate Dynamic Forms

Sorry that makes no sense. Add or remove from what fieldname since we do not know the name? How do you validate the name of the field when the name is generated dynamically?

 

User makes a quiz with 20 questions,  15 questions that will need a text area, the other 5 are yes/no radio inputs.

There are no names such as password, email as you noted in overriding validation the fields are dynamic so there is no way to know the name to hardcode it ahead of time.

 

Field names end up being : " name="data[Question][q-123asd569yhu]", we do not know the names of the fields

 

<input type="text" id="QuestionQ1" class="form-control" name="data[Question][q1]">

<input type="text" id="QuestionQ2" class="form-control" name="data[Question][q1]">

<input type="text" id="QuestionQ3" class="form-control" name="data[Question][q1]">

<input type="text" id="QuestionQ4" class="form-control" name="data[Question][q1]">

<input type="text" id="QuestionQ5" class="form-control" name="data[Question][q1]">…… and so on

<input type="text" id="QuestionQ123456789" class="form-control" name="data[Question][q123456789]">

 

 

From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of Stephen S
Sent: Thursday, May 22, 2014 4:56 PM
To: cake-php@googlegroups.com
Subject: Re: Validate Dynamic Forms

 

You can add and remove validation rules on the fly before you check if the form is valid.

 

 

On 22 May 2014 19:50, Advantage+ <movepixels@gmail.com> wrote:

I am building a questionnaire where the user can add questions to a form (either yes or no or text answer response)

So the Question has id, quiz_id, question, type (text or true / false),

 

But how would you validate this?

 

In the view I simply do a foreach ($questions as $question){

echo $this->Form->input($question['question']['id'], array(

                                                'label' => $question['Question']['question'],

                                                'type' => $question['Question']['type'],

                                                'div' => false));

 

But how do you validate this since model validation will not know these input / field names

The fieldname will be dynamic.

 

Thanks,

 

Dave

 

 

 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.



 

--
Kind Regards

 Stephen Speakman

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: