NYCPHP Meetup

NYPHP.org

[nycphp-talk] mystery parameter for process method in PEAR HTML_QuickForm

Dan Cech dcech at phpwerx.net
Tue Jun 15 23:51:21 EDT 2004


Jayesh Sheth wrote:
> In the slide at this address - 
> http://www.sklar.com/talks/show.php/nyphp-quickform/5 - there is this 
> snippet of code:
> 
> $form->process('say_hello');
> /* ... */
> 
> function say_hello($data) {
>     print 'Hello, ' . $data['my_name'];
> }
> 
> So, where does the $data information come from? Is it somehow implicitly 
> passed through to the say_hello() callback function when the 
> "$form->process('say_hello');" statement is made?

Yes, the line:

$form->process('say_hello');

is basically telling HTML_Quickform to grab all the submitted data from 
the form and send it as the first parameter ($data) to the 'say_hello' 
function.

In the code below, the line:

return call_user_func($callback, $values);

is equivalent to:

return $callback($values);

or:

return say_hello($values);

where $values is the data you submitted to the form.

Dan

> The code for the process method from the HTML/QuickForm.php file is as 
> follows:
> // *****************************************************
> /**
>      * Performs the form data processing
>      *
>      * @param    mixed     $callback        Callback, either function 
> name or array(&$object, 'method')
>      * @param    bool      $mergeFiles      Whether uploaded files 
> should be processed too
>      * @since    1.0
>      * @access   public
>      * @throws   HTML_QuickForm_Error
>      */
>     function process($callback, $mergeFiles = true)
>     {
>         if (!is_callable($callback)) {
>             return PEAR::raiseError(null, QUICKFORM_INVALID_PROCESS, 
> null, E_USER_WARNING, "Callback function does not exist in 
> QuickForm::process()", 'HTML_QuickForm_Error', true);
>         }
>         $values = ($mergeFiles === true) ? 
> HTML_QuickForm::arrayMerge($this->_submitValues, $this->_submitFiles) : 
> $this->_submitValues;
>         return call_user_func($callback, $values);
>     } // end func process
> // *******************************************************





More information about the talk mailing list