[symfony-users] Re: Form validation
On 16 fév, 00:02, Christophe COEVOET wrote: > Le 15/02/2011 23:57, Lideln a crit : > > > Since I cannot add new answers to the topic I created earlier (why > > that ?), I create a new one here with additionnal info. > > > As I said, I followed the official tutorial to create a RegisterForm > > and using it to register new members. > > But I got stuck at the validation, because I got the error : > > The option "validator" is required for validating > > > Here is my code, please can you tell me what I did wrong ? > > > [config.yml] > > app.config: > > error_handler: null > > validation: { enabled: true, annotations: true } > > > [controller] > > $oRequest = new RegisterRequest(); > > $oForm = RegisterForm::create($this->get('form.context')); > > You need to provide the name of the form here as a second argument. The > doc of the master has been fixed for this point. > > Regards > > -- > Christophe | Stof Hi Christophe, Thanks for the answer ! Yes I have been told that (although my method seems to work as well). Do you have any tips regarding the error I got ? (I'm sorry I created another topic, if an admin car move it please ?) -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en
[symfony-users] Re: Form Validation
Thanks a lot! I've just found the solution before your post! Thanks anyway for your contribution and help. :* On 2 déc, 21:14, Alexandre Salomé wrote: > Hi, > > Welcome to symfony :) > > You must set a postValidator on the validatorSchema of your form. > > In the configure() method of your form : > > public function configure() > { > $this->setPostValidator(new sfValidatorSchemaCompare("left_field", > sfValidatorSchemaCompare::GREATER_THAN, "right_field")); > > } > > Is it OK ? > > Alexandre > > 2009/12/2 WEB-CHALLENGE > > > > > Hi everybody! > > > I'm a new Symfony User. > > > I want to setup a form where the user can enter many values. > > > But, in the validation, the form won't be valid unless a certain data > > [an integer field] is greater than an other also entered by the user. > > > I think it's simple but I'm really novice in Symfony environnement. > > > Thanks > > > -- > > > You received this message because you are subscribed to the Google Groups > > "symfony users" group. > > To post to this group, send email to symfony-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > symfony-users+unsubscr...@googlegroups.com > > . > > For more options, visit this group at > >http://groups.google.com/group/symfony-users?hl=en. > > -- > Alexandre Salomé -- alexandre.sal...@gmail.com -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@googlegroups.com. To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en.
[symfony-users] Re: Form validation
Ok, it was easier than what I thought: $this->validatorSchema['CodFiscale'] = new sfValidatorAnd(array(new sfValidatorString(array('min_length' => 16, 'max_length' => 16), array ('min_length' => 'Il Codice Fiscale è troppo corto, deve essere di 16 caratteri', 'max_length' => 'Il Codice Fiscale è troppo lungo, deve essere di 16 caratteri'; $this->validatorSchema['CodFiscale']->setOption('required', false); On 19 Ago, 20:31, Stefano wrote: > It looks like if I define a validatorSchema for a field, the field is > Required. > > Since I need to validate a field, but only if it is not empty (I wrote > a custom validator to handle the empty field case), I get a Required > error I can not get rid of. > > Any suggestion? > > TIA > > Stefano --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation
Ciao Richtermeister, I wrote the validator as a Callback: widgetSchema['DataInizioValidita'] = new sfWidgetFormI18nDate (array('culture' => 'it_IT', 'month_format' => 'short_name')); $this->validatorSchema->setPostValidator(new sfValidatorCallback (array('callback' => array($this, 'checkSoglie'; } public function checkSoglie($validator, $values) { $trovataSoglia = false; if ($values['Importo'.$i] >= $values['Importo'.($i - 1)]) { throw new sfValidatorError($validator, "Ogni importo deve essere inferiore al precedente. (Importo$i)"); return $values; } } return $values; } } and I put it in lib/form/Form.class.php. It's form and problem specific, so I'm not going to reuse the logic anywhere in the project. I wonder if this is the right place where to put the code!? Now I'm looking for a way to highlight the wrong fields (with a red border, like the standard validators do) to the user... Stefano On 12 Ago, 20:34, Richtermeister wrote: > Hey Stefano, > > I would write a custom post-validator. A post validator is given the > entire data array, so from there you can just loop over the array and > see if the values keep increasing.. > > Hope this helps, > Daniel > > On Aug 12, 8:57 am, Stefano wrote: > > > Hi, > > > I'm developing my first web-application and I'm still RTFM (Reading > > The Fabulous Manuals), but I need a little help with a form > > validation. > > > For this application I'm using the Admin Generator. > > > The form contains 5 target fields: T1, T2, T3, T4, T5; every target > > must be greater than the previous: T1 < T2 < T3 < T4 < T5. > > > But only T1 is required while the other targets can be empty. > > > If a target is empty all the next ones must be empty. > > > So: > > T1= 100, T2= 200, T3=empty, T4=empty, T5=empty is valid, > > but: > > T1=100, T2=empty, T3=200, T4=empty, T5=empty is NOT valid. > > > I'm putting some code in lib/form/Form.class.php: > > > class ListinoForm extends BaseListinoForm > > { > > public function configure() > > { > > $this->validatorSchema->setPostValidator(new sfValidatorAnd(array > > (new sfValidatorSchemaCompare('T1', > > sfValidatorSchemaCompare::LESS_THAN, 'T2'; > > } > > > } > > > but I don't know how to test if a field is empty and I'm afraid that > > the resulting instruction will be very hard to read. > > > Any hint? > > > TIA > > > Stefano > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation
Hey Stefano, I would write a custom post-validator. A post validator is given the entire data array, so from there you can just loop over the array and see if the values keep increasing.. Hope this helps, Daniel On Aug 12, 8:57 am, Stefano wrote: > Hi, > > I'm developing my first web-application and I'm still RTFM (Reading > The Fabulous Manuals), but I need a little help with a form > validation. > > For this application I'm using the Admin Generator. > > The form contains 5 target fields: T1, T2, T3, T4, T5; every target > must be greater than the previous: T1 < T2 < T3 < T4 < T5. > > But only T1 is required while the other targets can be empty. > > If a target is empty all the next ones must be empty. > > So: > T1= 100, T2= 200, T3=empty, T4=empty, T5=empty is valid, > but: > T1=100, T2=empty, T3=200, T4=empty, T5=empty is NOT valid. > > I'm putting some code in lib/form/Form.class.php: > > class ListinoForm extends BaseListinoForm > { > public function configure() > { > $this->validatorSchema->setPostValidator(new sfValidatorAnd(array > (new sfValidatorSchemaCompare('T1', > sfValidatorSchemaCompare::LESS_THAN, 'T2'; > } > > } > > but I don't know how to test if a field is empty and I'm afraid that > the resulting instruction will be very hard to read. > > Any hint? > > TIA > > Stefano --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form Validation based on a tainted value?
That was exactly what I was looking for. Thanks, been staring at it for a while now! On Jul 26, 9:01 pm, Gábor Fási wrote: > I'm not sure I get what you mean. If you want to make sure one date is > later than another one, I suggest you set up an > sfValidatorSchemaCompare [1] instance as a post validator. > > [1]http://www.symfony-project.org/forms/1_2/en/B-Validators#chapter_b_su... > > > > On Sun, Jul 26, 2009 at 21:35, johnwards wrote: > > > Hello, > > > I have a form containing dates, I have two fields called: > > > Auction date > > Baseline required by > > > Auction date must be after the baseline date, now I can do this on > > existing objects by using the date validator and the "min" field. > > However, I need the tainted value for edits and new data. The tainted > > values are not avaliable until after bind. > > > Now I could overload the bind method and then call my setup of > > validators after then but this seems wrong, especially since bind uses > > the validators...so I'd have to call them twice?? > > > I'm sure I am missing something here...help. > > > Cheers > > John --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form Validation based on a tainted value?
I'm not sure I get what you mean. If you want to make sure one date is later than another one, I suggest you set up an sfValidatorSchemaCompare [1] instance as a post validator. [1] http://www.symfony-project.org/forms/1_2/en/B-Validators#chapter_b_sub_sfvalidatorschemacompare On Sun, Jul 26, 2009 at 21:35, johnwards wrote: > > Hello, > > I have a form containing dates, I have two fields called: > > Auction date > Baseline required by > > Auction date must be after the baseline date, now I can do this on > existing objects by using the date validator and the "min" field. > However, I need the tainted value for edits and new data. The tainted > values are not avaliable until after bind. > > Now I could overload the bind method and then call my setup of > validators after then but this seems wrong, especially since bind uses > the validators...so I'd have to call them twice?? > > I'm sure I am missing something here...help. > > Cheers > John > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation in symfony1.2
Hi jmaicher, Thanks For you Reply. iam searching for form validations without using of widgets. If you have any Idea Please Help me. Regards, Prashanth On Mar 31, 6:53 pm, jmaicher wrote: > It's pretty simple .. you created a class which extends sfForm?! > If so you just have to implement the configure()-function where you > can create widgets (I hope you did that so far). > With $this->setValidators you can specify validators for each widget > or you can add a post validator. > > little example > [code] > class emailForm extends sfForm > { > public function configure() > { > $this->setWidgets(array( > "email" => new sfWidgetFormInput(), > )); > > $this->widgetSchema->setLabels(array( > "email" => "E-Mail", > )); > > $this->setValidators(array( > "email" => new sfValidatorEmail(array(), > array("invalid" => > "Invalid email")) > )); > }} > > [/code] > > On 31 Mrz., 12:51, Prashanth wrote: > > > Thank you Very much For your Reply. > > And iam in little confusion where i have to write that code. > > Please Can you give the Example. > > > On Mar 23, 8:26 pm, Fási Gábor wrote: > > > > You can use the validators described in the Forms book, appendix > > > Bhttp://www.symfony-project.org/book/forms/1_2/en/B-Validators > > > they can be used w/o the form framework. > > > > On Mon, Mar 23, 2009 at 07:10, Prashanth wrote: > > > > > Hi All, > > > > > iam working with symfony 1.2. > > > > i have created the forms without using the widgets. > > > > So please can any one help me How Can i validate the Form in > > > > Symfony1.2. > > > > Thanks in Advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation in symfony1.2
It's pretty simple .. you created a class which extends sfForm?! If so you just have to implement the configure()-function where you can create widgets (I hope you did that so far). With $this->setValidators you can specify validators for each widget or you can add a post validator. little example [code] class emailForm extends sfForm { public function configure() { $this->setWidgets(array( "email" => new sfWidgetFormInput(), )); $this->widgetSchema->setLabels(array( "email" => "E-Mail", )); $this->setValidators(array( "email" => new sfValidatorEmail(array(), array("invalid" => "Invalid email")) )); } } [/code] On 31 Mrz., 12:51, Prashanth wrote: > Thank you Very much For your Reply. > And iam in little confusion where i have to write that code. > Please Can you give the Example. > > On Mar 23, 8:26 pm, Fási Gábor wrote: > > > You can use the validators described in the Forms book, appendix > > Bhttp://www.symfony-project.org/book/forms/1_2/en/B-Validators > > they can be used w/o the form framework. > > > On Mon, Mar 23, 2009 at 07:10, Prashanth wrote: > > > > Hi All, > > > > iam working with symfony 1.2. > > > i have created the forms without using the widgets. > > > So please can any one help me How Can i validate the Form in > > > Symfony1.2. > > > Thanks in Advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation in symfony1.2
Thank you Very much For your Reply. And iam in little confusion where i have to write that code. Please Can you give the Example. On Mar 23, 8:26 pm, Fási Gábor wrote: > You can use the validators described in the Forms book, appendix > Bhttp://www.symfony-project.org/book/forms/1_2/en/B-Validators > they can be used w/o the form framework. > > On Mon, Mar 23, 2009 at 07:10, Prashanth wrote: > > > Hi All, > > > iam working with symfony 1.2. > > i have created the forms without using the widgets. > > So please can any one help me How Can i validate the Form in > > Symfony1.2. > > Thanks in Advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation in symfony1.2
I think you should use widgets in sf1.2 to for validation. Its not that much difficult to use it rather i think its easier than ordinary form and validations used before. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation in symfony1.2
You can use the validators described in the Forms book, appendix B http://www.symfony-project.org/book/forms/1_2/en/B-Validators they can be used w/o the form framework. On Mon, Mar 23, 2009 at 07:10, Prashanth wrote: > > Hi All, > > iam working with symfony 1.2. > i have created the forms without using the widgets. > So please can any one help me How Can i validate the Form in > Symfony1.2. > Thanks in Advance. > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation as array
Hi, You have to create an edit.yml ( edit is your form submit action ) like this: methods: post: - "feedback{name}" - "feedback{email}" - "feedback{message}" names: feedback{name}: required: yes required_msg: Insert a title. . Try this.. ;) Regards. Mauro Casula symfony-framework.com On Tue, Jun 3, 2008 at 8:39 AM, hudson <[EMAIL PROTECTED]> wrote: > > Hello! > > I hawe a form: > > [CODE] > > > > > > [/CODE] > > When I submit this form - I'll get on the server-side an array: > > [CODE] > $feedback = array ( > "name"=> 1, > "email" => 2, > "message" => 3 > ); > [/CODE] > > How can I validate this form? > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: form validation <--> model validation
Thomas Rabaix wrote: > The original propel project handle validation at the Model level. This > feature has not been kept on symfony, don't know why ... Firstly, please don't cross post! :) Secondly, whilst I don't know why it was not done this way - but validating things in the model doesn't always make sense. For example, it might be a requirement that usernames are 6 or more characters, but an admin creating a user should be allowd to bypass this. Also when you're validating groups of models, that each might validate on their own, but as a group would be invalid... Maybe the feature was not kept for these kind of reasons, I'm not sure. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation problem
I am was having this and some other validation errors documented here: http://www.symfony-project.com/forum/index.php/m/35804/#msg_35804 I'll try to see if the fix above works, thanks. Smells like a bug to me. On 19 сент, 13:35, nico_bl1nd <[EMAIL PROTECTED]> wrote: > thanks Kiril, > > it works really well. > > I'll test more later why it doesn't want to take my post declarations > at the beginning. > > Thanks again > > Nicolas Binet --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation problem
thanks Kiril, it works really well. I'll test more later why it doesn't want to take my post declarations at the beginning. Thanks again Nicolas Binet --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Form validation problem
nico_bl1nd wrote: > Hi, > > I got some problem with the validation of form. > When I first get on the form, I get this error : > Notice: Array to string conversion in /usr/local/php5/lib/php/symfony/ > util/sfToolkit.class.php on line 329 > > And then when I validate my form, the sfStringValidator is not checked > by the system. > > Does anyone have any idea ? > > thanks > > Nicolas Binet > > Ps: My create.yml file > > methods: > post: > - "customer{name}" > - "customer{base_domain}" > - "customer{max_date}" > - "customer{max_partners}" > - "customer{max_learner}" > - "customer{max_storage}" > > names: > customer{name}: > required: yes > required_msg: Veuillez saisir un nom > sfStringValidator: > values: [foo, bar] > values_error: The only accepted values are foo and bar > insensitive: false > min: 2 > min_error:Please enter at least 2 characters > max: 100 > max_error:Please enter less than 100 characters > > customer{base_domain}: > required: yes > required_msg: Veuillez saisir une url pour le client > > customer{max_date}: > required: yes > required_msg: Veuillez saisir une date pour la fin de contrat > > customer{max_partners}: > required: yes > required_msg: Veuillez saisir un nombre maximum de partenaires > > customer{max_learner}: > required: yes > required_msg: Veuillez saisir un nombre maximum d'apprenants > > customer{max_storage}: > required: yes > required_msg: Veuillez saisir une limite pour le stockage > autorisé > > > > > > Interesting. I am not that into the validation systems and tried your validation yml file and got the same results. Seems like with names: you cannot go deeper that second level. For example: names: customer{base_domain}: required: msg: Veuillez saisir une url pour le client The above does not work. You have to do: names: customer{base_domain}: required: yes required_msg: Veuillez saisir une url pour le client but if you use fields: instead of names: then you can put validators and such. I think you are misunderstanding the use of names: and I could not find anything in the Symfony book which can shed more light on the issue. You can use the following validation yml file I came up with: fields: customer{name}: required: msg: Veuillez saisir un nom sfStringValidator: values: [foo, bar] values_error: The only accepted values are foo and bar insensitive: false min: 2 min_error:Please enter at least 2 characters max: 100 max_error:Please enter less than 100 characters customer{base_domain}: required: msg: Veuillez saisir une url pour le client customer{max_date}: required: msg: Veuillez saisir une date pour la fin de contrat customer{max_partners}: required: msg: Veuillez saisir un nombre maximum de partenaires customer{max_learner}: required: msg: Veuillez saisir un nombre maximum d'apprenants customer{max_storage}: required: msg: Veuillez saisir une limite pour le stockage autorisé --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---