[Solar-talk] Question about using forms
Paul M Jones
pmjones at ciaweb.net
Tue Nov 20 18:09:15 CST 2007
> On Nov 20, 2007 2:45 PM, Cruz, Darwin <Darwin.Cruz at gd-ais.com> wrote:
>> In my controller file i've created a from with two elements:
>>
>> $this->invForm= Solar::factory('Solar_Form');
>>
>> $this->invForm->setElement
>> ('user_email', array(
>> 'type' => 'text',
>> 'label' => 'Email Address:'
>> ));
>>
>>
>> $this->invForm->setElement
>> ('process', array(
>> 'type' => 'submit',
>> 'label' => 'Action:',
>> 'value' => 'Save',
>> ));
>>
>> In my corresponding view i have the following to show the form i
>> have created:
>>
>>
>> <?php
>> echo $this->form($this->invForm(user_email));
>> ?>
>>
>> In the view both the text box and the submit button are shown.
>> But i'm trying to break those up to be formatted in a table i'm
>> building. My question is, how can i only show the user_email
>> portion of the form?
>>
On Nov 20, 2007, at 5:33 PM, Raymond Kolbe wrote:
> Do you mean, how can you separate the form elements so that a
> portion of the form (e.g. a text field) will show in a cell in the
> table?
>
> If this is the case, I came across the same problem the other day
> and came to the conclusion that (currently) it can not be done. The
> reason being because Solar_Form constructs everything and when fetch
> () is called, pukes it all out.
"Pukes" is not quite the word I would use. "Prints" is much nicer.
> Maybe I am wrong and there is a way to do this, but I haven't found
> a way yet. I suppose you could extend Solar_View_Helper_Form and
> create a couple of methods that return certain elements along the
> way (e.g. fetchField($itemToFetch).
>
> Let me know if I am in left field.
Not in left field, exactly, but it can be done. It's just not fully
automated.
Darwin, there are two solutions: a full-manual approach, and a semi-
automatic approach.
The full-manual approach is to use the individual form element
helpers, like so.
echo $this->formInput($this->invForm->elements['user_email']);
That will output just the <input> tag with the information from the
user_email element. You get no messages, no labels, none of the cool
stuff -- but you have full control over the placement and the
surrounding XHTML. You can additionally access the elements[] array
to get label and validation messages, and manually place them any way
you like.
The semi-automatic approach uses the form helper element methods to
intersperse XHTML where you want it, along with groupings, but you're
stuck with the <dl></dl> CSS-based approach then.
echo $this->form()
->xhtml('<div name="foo">')
->input(this->invForm->elements['user_email'])
->xhtml('</div>')
->fetch();
The main benefit of this approach is that you can start using the
built-in fieldset and grouping methods very easily, without having to
mix in raw XHTML, and it keeps all the validation messages and labels
in place.
echo $this->form()
->beginFieldset('Email Information')
->input(this->invForm->elements['user_name'])
->input(this->invForm->elements['user_email'])
->beginGroup('Actions')
->submit($this->invForm->elements['save'])
->submit($this->invForm->elements['cancel'])
->reset($this->invForm->elements['reset'])
->endGroup()
->endFieldset()
->fetch();
While this helps with CSS based forms and (pseudo-) semantic XHTML,
it probably won't do the trick for you if you're required to use
tables for forms.
Perhaps it's time for an additional table-based form helper? Happy
to take contributions there.
Hope this helps, let me know if it does not.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the Solar-talk
mailing list