[Dbix-class] Generic database record form editor ...

Zbigniew Lukasiak zzbbyy at gmail.com
Tue Jan 12 11:31:41 GMT 2010


On Sun, Jan 10, 2010 at 11:03 AM, Kiffin Gish <kiffin.gish at planet.nl> wrote:
> I'm in the process of creating a generic database record editor form in
> which the writable columns can be edited and updated. Something similar
> to what phpMyAdmin does.
>
> The idea is that the form is generated on-the-fly where columns of
> data_type 'text' result in input text, those columns with a one-to-many
> relationship in multiple select, belongs_to in a normal single select,
> boolean in checkbox, 'datetime' in a date-picker, etc.
>
> The columns defining relationships will automatically pull in the
> possible values and fill the select.
>
> Primary keys, datetime last_modified, etc. will be visible but disabled
> 'readonly' input fields.
>
> This is a doable project but alot of work, so I was wondering if this
> has already been done and where I could look for inspiration.
>

If you are using HTML::FormHandler then you can have a look at
Catalyst::Example::InstantCRUD which generates something like that.
There might be some need to update it to use the newer FormHandler
ideas (like the reflection layer being worked on by rafl).

Cheers,
Zbigniew

> Below is an example I currently use which isn't very flexible but gives
> one a better idea what I mean.
>
> ---start---
>
> <form action="[% c.uri_for(c.controller('Users').action_for('edit'),
> [user.id]) %]" method="post" accept-charset="utf-8">
> <table>
> [% FOREACH col = users_rs.result_source.columns -%]
>    [% IF (col == 'id' || col == 'username' || col == 'last_modified');
> ro = ' readonly="readonly"'; ELSE; ro = ''; END %]
>    <tr>
>        <td>[% col %]</td>
>        <td> : </td>
>    [% IF col == 'status' %]
>        <td><select name="status" size="1">
>        [% WHILE (status = user_status_rs.next) %]
>            <option value="[% status.id %]"[% IF (status.status ==
> user.user_status.status) %] selected="selected" [% END %]>[%
> status.status %]</option>
>        [% END %]
>        </select></td>
>    [% ELSE %]
>        [% IF col == 'password' %]
>        <td><input type="password" name="password" value="[% user.$col
> %]"/><br />
>            <input type="password" name="password2" value="[% user.$col
> %]"/></td>
>        [% ELSE %]
>        <td><input type="text" name="[% col %]" value="[% user.$col
> %]"[% ro %]/></td>
>        [% END %]
>    [% END %]
>        <td>[% IF errors.$col %]<span style="color:red">[% errors.msg
> %]</span>[% END %]</td>
>    </tr>
> [% END -%]
>        <td></td><td></td><td><input type="submit"
> value="Update"/><input type="button" value="Cancel"
> onclick="window.location='[%
> c.uri_for(c.controller('Users').action_for('profile'), [user.id]) %]'"/>
> </td><td></td></tr>
> </table>
> </form>
>
> ---end---
>
> Thanks alot in advance!
> Kiffin
>
>
> --
> Kiffin Gish <Kiffin.Gish at planet.nl>
> Gouda, The Netherlands
>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>



-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/



More information about the DBIx-Class mailing list