how add validator field dynamicaly in the php file
how add validator field dynamicaly in the php file
Hello everybody.
In my edotor i add somme fields dynamicaly with add() fonction in a loop. I would like to add validator in my php file for all the fields adding in the js file. How can i add dynamicaly in a loop the validator for every fields adding.
Thanks for your help.
Lionel
Answers
Just define the Editor fields in PHP. In the validator check whether or not the field is set and then do the validation.
Here is an example from my own coding: Only if "sub.sub_name" is set is a real validation being executed:
Just to add to rf1234's response. You must do validation at the server-side (or to wherever you are submitting your data), so the approach I usually take with Editor is to just ignore the client-side validation - an Ajax submission is virtually free compared to the developer time needed to duplicate and maintain two sets of validation.
You can dynamically add fields on the server-side as well. The exact answer will depend upon how you are adding and naming the fields and how the server-side handles them.
Allan
Thank you for your answers.
I do validation in the server side by using Field::inst and -> validator.
In the client side (js file) i add fields with this loop:
And the ajax submission is like this
I would like to add in the server side the number of Field::inst and -> validator with the good name. Maybe by a loop varying from 1 to data[0][data_life_table][number].
I don't know if it's possible and how i can do that.
Thanks thanks a lot.
Lionel
Can you show me how you are defining the fields on the server-side please? Are you using a loop or something? Or is the problem not just the validator, but that you don't know how to add that number of fields?
If you add a dynamic number of fields, how are you storing it in the database? Say your database had 10 columns available for these dynamic values, but the user submitted 11 - what happens?
Allan
I made a logic error while trying to improve my code.
Your answer made me realize this error. I'm sorry for the time you wasted with my question.
I would certainly have another question but I have to find the words to make you understand what I do and for what purpose.
Thank you very much for everything.
HL
No worries. Good to hear you got that one sorted.
Allan