On 2/24/06, Aaron Trevena <[EMAIL PROTECTED]> wrote:

> The docs aren't really available - it's just that I find it a pain in
> the arse to do forms using CGI::Untaint and the current AsForm, with
> plain CDBI classes.
>
> Essentially you have several things affected by whether a field is
> required or not:
>
> * Foreign Relation Select lists
>   - These should have a null option, if the field isn't required

Should be easy enough to do in AsForm.

> * Untainting of a field
>   - An empty field should not result in an error if the field is not
> required but should be validated if present, and should also remove
> the value in the database if blank

I had to hack Untaint and FromCGI.  to fix all these issues.

> * Displaying hints for fields
>   - A required field should be marked as such in a form
>

 I use IF ELSE in template and check required_cols :
  <div class="row">
        [% IF (required.$col); %]
        <span class="required">
           * [% classmetadata.colnames.$col || col FILTER ucfirst  %] :
        </span>
        [% ELSE; %]
        <span class="label">
            [% classmetadata.colnames.$col || col FILTER ucfirst  %] :
        </span>
        [% END; %]
        <span class="formw">
            [% elem.as_XML; %]
        </span>
        <span class="error">
            [% IF errors.$col; errors.$col; ELSE; "&nbsp;"; END; %]
        </span>
    </div>

> The current Maypole::Model::CDBI::AsForm checks if a field is
> nullable, based on the examples peter provided in the other progess
> thread :
>
> 1) checks args->{column_nullable}
> $beer->to_field(brewery, {column_nullable => 1, column_default => undef });
>
> 2) It tries to call $model->column_nullable
> $beer->to_field('brewery');
>
> CGI::Untaint checks if a list of 'required_cols' and 'ignore_cols' are
> provided, this is affected by using the untaint command and I want to
> look into documenting how this works as it has annoyed me greatly on
> my last project and is starting to grate on this one.

You mean FromCGI checks required cols and ignore cols.

>
> I want to be able to say what is required, or not and then it be
> handled correctly when displaying and validating forms.
>
> My proposal is being able to specify which columns are required, and
> using this information to set everything else.
>
> for example :
>
> MyApp::Job->columns(All => qw/Title Salary FAO Closing_Date
> Description Location/);
> MyApp::Job->has_a(Location => 'MyApp::Location');
>
> MyApp::Job->untaint_columns(
> printable => [qw/Title Salary Description/],
> date => ['Closing_Date'],
> email => ['FAO'],
> integer => ['Location']
> );
>
> MyApp::Job->required_columns(qw/Title Salary FAO Closing_Date/);

Yep. Need a separate FromCGI to do all you want to do i believe.   I
made a start on one with code pasted from my Model.   It will give you
and idea of what i had to do to overcome flaws in FromCGI. A lot of
its complexity is dealing with foreign inputs and processing those
automatically. That code should not get in the way of creating simple
objects its just not pretty.

see if it works. I will later.

Attachment: FromCGI.pm
Description: Binary data

Reply via email to