[Solar-talk] Form submission help
Raymond Kolbe
rkolbe at gmail.com
Sat Jul 21 20:09:42 CDT 2007
Rodrigo,
Thank you for your help!
Note: Most of this email was written while I was trying to resolve my
issue...I have since then resolved my issue but think it is worth
mentioning my error and the solution to it.
I suppose that echo $this->form()->auto($this->form)->fetch(); would
make sense to grab the form.
That being said, I did try taking _auth.php from the Solar_App_Base
Layout directory and tried to replicate the way it is used there. It
makes use of $this->form()...->fetch() and it outputs my form just
fine. My issue at this point is to have my action pick up on the
submission of data..
Example (non-functioning/sample code):
//------Vendor/App/Preferences.php-----//
class Vendor_App_Preferences
function actionChangePassword(){
$request = Solar::factory('Solar_Request');
// get the requested process
$process = $request->post('process');
// handle processes based on the localized button values
if ($process == $this->locale('PROCESS_UPDATEPASSWORD')) {
// I just wanted to change something to verify that the form is working
$this->layout_head['title'] = 'Updated your password';
}
}
//-----End Vendor/App/Preferences.php-----//
//-----Vendor/App/Preferences/View/changepassword.php-----//
echo $this->form()
->hidden(array(
'name' => 'process',
'value' => $this->getTextRaw('PROCESS_PASSWORDUPDATE')
))
->password(array(
'name' => 'passwd1',
'label' => $this->getTextRaw('LABEL_PASSWD1'),
'attribs' => array('size' => 10),
))
->password(array(
'name' => 'passwd2',
'label' => $this->getTextRaw('LABEL_PASSWD2'),
'attribs' => array('size' => 10)
))
->submit(array(
'name' => 'process',
'value' => $this->getTextRaw('PROCESS_PASSWORDUPDATE')
))
->fetch();
//-----End Vendor/App/Preferences/View/changepassword.php-----//
When I view Preferences/ChangePassword it shows the form just fine,
etc. But like I said before, it is not actually picking up on the
submission of data.
As mentioned in the note at the beginning of this email, I found my
issue and have since then fixed it. The issue was that my locale name
"PROCESS_PASSWORDUPDATE" was incorrect in the action (which was named
"PROCESS_UPDATEPASSWORD").
As a side question, without directly instantiating/adding it to the
factory, how does Solar know to what $this->form is? I drilled down
the class hierarchy and couldn't find anything off hand. I know that
the bookmark application uses Solar_Content_Abstract and that happens
to call form which adds Solar_Form to the factory...My Vendor
directory though has the bookmark application omitted yet I am still
able to call form() without a hitch.
Thank you again for your through response ;) I'll have to hop on over
to IRC soon to join in on the Solar fun ^_^
--Raymond Kolbe
On 7/21/07, Rodrigo Moraes <rodrigo.moraes at gmail.com> wrote:
> Hi, Raymond.
> Welcome to Solar. :)
>
> On 7/21/07, Raymond Kolbe
> > However, in order to preserve the MVC aspect of things, wouldn't it be
> > best to put the form itself in the view (let's say,
> > changepassword.php), and put the 'nuts and bolts' of the code in the
> > model (this case being Vendor_App_ChangePassword)?
>
> It is indeed a good idea, and that's how we generally do. Forms can be
> loaded from models as you'll see later, and also can be set in a
> controller, or even directly in a view template. When using models, we
> commonly load forms from them, set the form in a controller property
> and them it is available in a view.
>
> The example you mentioned simplifies things a bit for didactic
> purposes; we don't use forms in a single file which instantiate a view
> object etc. But it serves well to demonstrate how Solar_Form works;
> although it seems to not have a 'form_example.view.php' template
> example. I guess this is what you miss to get the example working?
>
> Try this for 'form_example.view.php':
>
> <?php
> echo $this->form()->auto($this->form)->fetch();
> ?>
>
> Here, $this->form is the Solar_Form you have assigned to the view in
> the example from the manual. $this->form() is the form view helper,
> automatically loaded if you start the view and set the helper path to
> Solar/View/Helper, like this:
>
> $view = Solar::factory('Solar_View', array('helper_class' =>
> 'Solar_View_Helper'));
>
> (the second parameter passes the helper path configuration to Solar_View)
>
> Inside a view, you can print isolated form elements using view helpers
> (there is one for every kind of form element, check
> Solar/View/Helper), or you can use the form() view helper (like above)
> to build the HTML for an entire form.
>
> Was this helpful? I hope I understood your question, let me know if not. :)
>
> Hey, if you are interested, join our irc channel #solarphp at
> freenode.org to solve quick doubts. There are not many people there
> but if you're lucky somebody will not be away and can offer some help.
> :)
>
> -- rodrigo
> _______________________________________________
> Solar-talk mailing list
> Solar-talk at lists.solarphp.com
> http://mailman-mail3.webfaction.com/listinfo/solar-talk
>
More information about the Solar-talk
mailing list