[Solar-talk] Form submission help

Paul M Jones pmjones at ciaweb.net
Sat Jul 21 20:46:49 CDT 2007


On Jul 21, 2007, at 8:44 PM, Paul M Jones wrote:

> 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.)

Whoops, I can go one better on that.  The _isProcess() method is a  
little smarter than I typed above.  You can actually do this:

        if ($this->_isProcess('updatepassword')) { ...

The _isProcess() method upper-cases the word and prefixes with  
PROCESS_ for you, then translates that as a locale key, so you don't  
need to see all-caps everywhere in your code.



--

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