form validation

95 views
Skip to first unread message

amka...@gmail.com

unread,
Dec 3, 2016, 3:13:33 AM12/3/16
to Mojolicious
Hi,

I am new about Mojolicious and I need please some help ; it's about form validation.

This form, in a separate file, contains :

%= form_for protected => begin
....
<br>Z1:<br>
   %= text_field 'za', id => 'za'
  <br>
....
  %= submit_button 'OK'
% end

and my action contains :

use Mojolicious::Validator;
use Mojolicious::Validator::Validation;
...

    my $validator  = Mojolicious::Validator->new;
    my $validation = Mojolicious::Validator::Validation->new(validator => $validator);
    $validation = $validation->required('za');

    if (not $validation->has_error) {
...

Impossible to enter the " if " even if the field " za " is full ($self->param('za') works).
If I delete the " validation = $validation->required('za'); " line, then I enter the if.

I don't understand ; can someone help me ?

Thanks,

amka   :)


amka...@gmail.com

unread,
Dec 3, 2016, 7:55:41 AM12/3/16
to Mojolicious
And when I put

my $names = $validation->failed;

I have this message :

Can't locate object method "failed" via package "Mojolicious::Validator::Validation" at /home/amka/job/RAD/mojo/03/script/../lib/MyApp/Controller/En.pm line 35.


Jan Henning Thorsen

unread,
Dec 4, 2016, 8:48:07 AM12/4/16
to Mojolicious
Hey,

Not sure if I understand your problem, but why don't you just use $c->validation? Have a look here for more information and examples: https://metacpan.org/pod/distribution/Mojolicious/lib/Mojolicious/Guides/Rendering.pod#Form-validation

Which version of Mojolicious do you have? Run "mojo version" to check the version.

amka...@gmail.com

unread,
Dec 7, 2016, 1:52:36 AM12/7/16
to Mojolicious
Hi,

Your sample works !

One big problem is that when I put "use Mojolicious::Lite;" in the controller we speek about, the soft don't work more : I have this error message at login :

Page not found... yet!

None of these routes could generate a response for your GET request for /protected, maybe you need to add a new one


But I have in the main file, which worked before "use Mojolicious::Lite;" :


package MyApp;

use Mojo::Base 'Mojolicious';
use MyApp::Model::Users;

sub startup {
  my $self = shift;

  $self->secrets(['Mon applix! mojo premiere']);
  $self->helper(users => sub { state $users = MyApp::Model::Users->new });

  my $r = $self->routes;
  $r->any('/')->to('login#index')->name('index');
 
  my $logged_in = $r->under('/')->to('login#logged_in');
  $logged_in->get('/protected')->to('engrenage#roues');

  $r->get('/logout')->to('login#logout');
 
}

1;

My version :


amel@debian:~/job/RD/mojo/marc$ mojo version
CORE
  Perl        (v5.20.2, linux)
  Mojolicious (5.54, Tiger Face)

OPTIONAL
  EV 4.0+                 (4.18)
  IO::Socket::IP 0.20+    (0.32)
  IO::Socket::Socks 0.64+ (0.65)
  IO::Socket::SSL 1.84+   (2.002)

You might want to update your Mojolicious to 7.11.


Thanks a lot, best regards,


amka











Reply all
Reply to author
Forward
0 new messages