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

Kiffin Gish kiffin.gish at planet.nl
Sun Jan 10 11:03:39 GMT 2010


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.

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





More information about the DBIx-Class mailing list