Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Changing order of validation rules on a form question. How do I?

peregrineperegrine MVP
edited July 2013 in Development

This is a question?? not an answer :)

let's says there is a form

input 1
input 2
input 3

you add an input 4  and a validation rule for input 4

 if 4 is bad ....
 $Sender->Validation->AddValidationResult('input1',T('please enter input4'));
 $Sender->EventArguments['Valid'] = FALSE;

how do you get it to evaluate input1 2, and 3 rules first and then after that evaluate the rule you added in input4.

currently it seems to evaluate input4 before evaluating 1,2, or 3.

once 4 is correct if 1,2, or 3 display validation results.

I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

UnderDog

Comments

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited July 2013

    I might not understand the question these are the rules for my contact plugin

                    $Validation = new Gdn_Validation();
                    $Validation->ApplyRule('YourName', 'Required', 'You must enter your name.');
                    $Validation->ApplyRule('YourEmail', 'Email', 'You must enter your e-mail (will not be published).');
                    $Validation->ApplyRule('Message', 'Required',"You must include a Message");
                                $Validation->ApplyRule('Checkbox', 'Required',"You must check the box");
    

    You get a separate warning for each and also a combo depending on how many you missed filling out..

    peregrine
  • peregrineperegrine MVP
    edited July 2013

    I might not be presenting the question well. but you gave me the possible reason.

    I mistakenly said input4 had a rule added when in fact it didn't, just a test of the form input and then this was applied, that explains it, it never got to the other rules.

    $Sender->Validation->AddValidationResult('input1',T('please enter input4'));

    so it looks like i may need to create some custom rules and apply them.

    thanks, never occurred to me! doh!

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited July 2013

    Each one gets it's own error

    $Sender->Form->SetValidationResults($Validation->Results());
                if($Sender->Form->ErrorCount() == 0){
                    $Name = $FormValues['YourName'];
                    $Subject = sprintf('Contact From %s %s', $Name, date('j M Y H:i'));
                    $Email->Subject($Subject);
                    $Email->To( C('Garden.Email.SupportAddress', ''));
                    $Email->From($FormValues['YourEmail']);
                    $Email->Message($FormValues['Message']);
                    $Option=GetIncomingValue('Form/Checkbox');
    

    I would guess that without a rule it validates nothing ?

    peregrineUnderDog
  • peregrineperegrine MVP
    edited July 2013

    thx. we both edited messages.

    like I said I tested data received from form and did my own checking without applying a rule, I still manually validated but.... Unfortunately my own checking caused my rule to be tested first. where as it would have been sequential if I created a custom rule and then applied it using the proper methods. Just tried to take a shortcut, which didn't work the way i wanted.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
Sign In or Register to comment.