[Solar-talk] Form submission help
Paul M Jones
pmjones at ciaweb.net
Sat Jul 21 20:44:14 CDT 2007
On Jul 21, 2007, at 8:09 PM, Raymond Kolbe wrote:
> 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';
> }
> }
I know you've solved it, but here's some background info that might
make things easier in future:
* A request object already exists for your use; it's $this-
>_request. Strangely, I don't expect you'll need it in common
cases, because you have access to the the request portions you need
through other means. For example ...
* To check a process submission, you can use $this->_isProcess
('PROCESS_UPDATEPASSWORD'). That will do the locale translation and
$_request->post('process') value checking for you. (Good on you for
doing the locale translation, by the way -- lots of folks don't get
that so quickly, and have trouble localizing their apps later on.)
So the revised version would be:
function actionChangePassword()
{
// handle processes based on the localized button values
if ($this->_isProcess('PROCESS_UPDATEPASSWORD')) {
// I just wanted to change something to verify that the
form is working
$this->layout_head['title'] = 'Updated your password';
}
}
(or use PROCESS_UPDATEPASSWORD, whichever you settled on at the end.)
> As a side question, without directly instantiating/adding it to the
> factory, how does Solar know to what $this->form is?
Every public property of your Solar_Controller_Page object gets
passed into the view. So, $this->foo in the page controller becomes
$this->foo in the Solar_View object. Does that help at all?
> 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.
This relates to how the helpers get called. Basically, everything in
Solar/View/Helper/* can be called as a method through Solar_View.
Solar_View_Helper_Anchor, for example, gets automatically loaded when
you call $this->anchor() inside a view script. The
Solar_View_Helper_Form class gets called via $this->form(). So the
helper itself not dependent on the content object at all.
Now, the content objects do provide the ability to generate a form
processor object (Solar_Form) and load it up with elements related to
that content type. I think you get this already, but I'll reiterate:
Solar_Form is the processor, and provides "hints" about how to
generate output, but does not itself generate output.
Solar_View_Helper_Form can take the hints from a Solar_Form object
and generate output. That way we get good separation of concerns,
and can plug in or replace the separate concerns independent of each
other (as long as they behave as expected).
Hope that all makes sense, please let me know if it does not ... and
thank you for using Solar. Welcome aboard. :-)
--
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