Note that there are some explanatory texts on larger screens.

plurals
  1. POData::FormValidator prints hashref instead of string for invalid data
    text
    copied!<p>We develop a Catalyst app and my coworker started implementing form validation with <code>Catalyst::Plugin::FormValidator</code> which provides a shortcut to <code>Data::FormValidator</code>.</p> <p>The validation seems to succeed and the display of missing entries works. But when displaying details for mismatched constraints the page contains a hashref like <code>HASH(0x784d80)</code>.</p> <p>This is the hash we use to configure the validator (everything example code made up to test FormValidator first):</p> <pre><code>{ required =&gt; [qw/email age sex/], optional =&gt; [qw/city name/], filters =&gt; [qw/trim/], constraints =&gt; { name =&gt; sub { length $_[1] &gt;= 2 }, sex =&gt; sub { $_[1] =~ /^(male)|(female)$/}, age =&gt; sub { $_[1] =~ /^[0-9]{1,2}$/ }, email =&gt; sub { Email::Valid-&gt;address(lc($_[1])) }, city =&gt; sub { length $_[1] &gt;= 5 }, }, msgs =&gt; { invalid =&gt; { field =&gt; { email =&gt; 'no valid e-mail address', age =&gt; 'no valid age between 01 and 99', }, default =&gt; 'contains an invalid value', }, missing =&gt; 'missing!', }, } </code></pre> <p>This is how we read the values:</p> <pre><code> &lt;tr&gt; &lt;td&gt;E-mail address:&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="email" value="[% email %]" /&gt;* [% c.form.msgs.email %]&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>For missing fields everything works fine. For invalid fields the value given to <code>invalid =&gt;</code> is just printed out. If set to <code>invalid =&gt; "THIS IS INVALID!"</code> the string is printed and if set to <code>invalid =&gt; {}</code> the hashref is printed as e.g. <code>HASH(0x784d80)</code> (even for empty hash).</p> <p>Can somebody explain why this is? We use the current version 4.66 of <code>Data::FormValidator</code> from CPAN.</p> <p><strong>Update:</strong> By dumping <code>[% c.forms %]</code> my coworker could verify that the validity of the fields is determined correctly. Just the string is set wrong and we don't know why.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload