On 9/27/10 8:33 PM, Pascal wrote:
In this example how can i test if a field is in error ?

my proposal (looks very familiar ..)

<form action="#" method="post">

<?php echo $f->getErrors() ?>
<table>
<tr class="<?php echo $form->hasError('first_name') ? 'error' : '' ?>">
<th>
<?php echo $form->getLabel('first_name') ?>
</th>
<td>
<?php echo $form->getError('first_name') ?>
<?php echo $form->getField('first_name') ?>
</td>
</tr>

This is basically what I propose. To make my proposal clearer, we define two different helpers:

* The first helper knows about individual fields (errors, label, widget, ...) and also about global errors, hidden fields, embedded fields, ...

* The second helper knows about the structure of a form (table, rows, ...)

The first one comes with default templates that anybody can override (this is need to provide nice widget like an autocompleter for instance). This is easy, and you probably rarely need to change them.

As the second one is only about presentation (the form structure), we don't provide default templates, just the code needed to encapsulate the rendering. So, you write the templates, and you can reuse them for all your forms (or just some of them).

Fabien

But maybe it's too verbose, what do you guys think ?

[MA]Pascal

On Mon, Sep 27, 2010 at 18:25, Fabien Potencier
<[email protected]
<mailto:[email protected]>> wrote:


    On 9/27/10 6:59 PM, Yuen-Chi Lian wrote:

        If I can add an extra thing to what you suggested, I wish that
        $f->row()
        won't be rendering <li/> or <tr/>, as it may waste time for
        developers
        or designs to find a clean/dirty way to add custom objects into the
        HTML, e.g. a light bulb, some fancy tips, etc.


    Yes, you are right, if we get rid of ->group() method (the one used
    by echo $form), we must also remove ->row() as it does not make
    sense anymore.

    So, the minimum code would read as follows:

    <form action="#" method="post">

    <?php echo $f->errors() ?>
    <table>
    <tr>
    <th>
    <?php echo $form->label('first_name') ?>
    </th>
    <td>
    <?php echo $form->error('first_name') ?>
    <?php echo $form->field('first_name') ?>
    </td>
    </tr>

                    // ...

    </table>
    <?php echo $f->hidden() ?>
    <input type="submit" value="Update" />
    </form>

    So, basically, we provide helpers to help render individual data
    (errors, nice widgets, ...) but not the main structure of the form
    itself.

    Another possibility would be to keep the ->group() and ->row()
    methods but without providing any "default" template. It means that
    you must write those templates yourself if you want to use them.
    That way, you can implement the display logic you want project-wise
    for form structures, and you will be responsible for the "lack" of
    flexibility.


    Fabien

    --
    If you want to report a vulnerability issue on symfony, please send
    it to security at symfony-project.com <http://symfony-project.com>

    You received this message because you are subscribed to the Google
    Groups "symfony developers" group.
    To post to this group, send email to [email protected]
    <mailto:[email protected]>
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:symfony-devs%[email protected]>
    For more options, visit this group at
    http://groups.google.com/group/symfony-devs?hl=en




--
Pascal

--
If you want to report a vulnerability issue on symfony, please send it
to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to