There are two different ways to flag a method as a "formHandler".
Method 1: use the new ExtDirect::$form_handlers configuration option.
- name: form_handlers
- type: array of strings
- meaning: Name of the class/methods to be flagged as formHandler in the Ext.Direct API
- default: empty
- comments: The string format for each method must be "className::methodName".
Method 2: include "@formHandler" in the DOC comment of the method.
ExtDirect::$form_handlers = array( 'someClass::someMethod', 'Server::date' );
In the example above, due to the "@formHandler" string inside the method's DOC comment, it will be flagged as a "formHandler" method.
* Sets FTP password for a specific account
* @param string $account Name of the account
* @param string $password New password
* @param string $password_confirm New password confirmation
* @return string
public function set_ftp_password( $account, $password, $password_confirm )
// do stuff
It has the same effect as this:
* Receiving parameters *
ExtDirect::$form_handlers = 'FTP_Manager::set_ftp_password';
The parameters sent by forms are adapted to be received by the class method.
Pay attention now, because this is not usual.
I will use the "set_ftp_password" method above as the example.
First, note that we don't want that all formHandler methods have the same not-friendly signature, like this:
Where $data is the user input (usually $_POST)
function set_ftp_password( $data );
function do_something( $data );
function do_something_completely_different( $data );
So, to be able to keep normal method signatures, like this...
...I have implemented the following solution:
function set_ftp_password( $account, $password, $password_confirm )
When the method/action function is a formHandler, its parameter values are taken from the input names that matches the parameter's names.
So... $_POST['account'] will automatically become the $account parameter...
$_POST['password'] value will be the $password parameter value...
...and from where the $password_confirm parameter value will come from? Yes! From $_POST['password_confirm']
That's it: the method's parameters' names matches the $_POST array keys.
- Don't need to worry with parameter order
- Can use meaningful and clean method/function signature
- Don't need to sniff with $_POST array - the ExtDirect controller does this for us (forget "isset" checkings... if a certain parameter value is not set in the $_POST array, the default value - if available - or null is passed to the method/function)
- The input names must match the method/function parameter names (IMHO, an advantage!)
- This approach may just not be the best for you (in this case, just ignore all this stuff and go for the $_POST / $_GET / $_REQUEST arrays!)
Of course, all validation / filtering / sanitization of input data, as always, must be carefully considered.
Additional note about file upload:
If your file input name is "userfile", it will be available in your method/function parameter named $userfile
In other words: your $userfile parameter will receive the value from $_FILES['userfile']