post
function post($var, $default = null)
Returns element with name specified in the first parameter from the $_POST array. If element is not found, returns default value, specified in the second parameter. This function is useful for form processing.
Parameters
- $var - string. Specifies POST element name to return.
- $default - mixed, default NULL. Specifies a default element value.
Return value
Returns mixed value.
Examples
The following code fetches the 'name' POST element and if there is no such element, uses string "John".
$name = post('name', 'John');
Next: post_array_item
Previous: option_state
Return to Reference


Comments
Jeffrey Bennett
Tuesday, April 26, 2011I'm curious if there is a get() function equivalent to this or some way to retrieve information from the URL. Thanks for your help!
Aleksey Bobkov
Tuesday, April 26, 2011@Jeffrey - there is no a helper function for the GET data yet, but there is the getField() method in the Request class. Example: Phpr::$request->getField('name') or Phpr::$request->getField('name', 'default value').
Silas Bondrup-Nielsen
Tuesday, August 30, 2011I am trying to get an array from POST. I see there is a post_array_item() method, but I don't want to get elements from an associated array. I want to get a full indexed array. I have several checkboxes with the same name but different values. I know if I used $_POST['my_name'] I should get an array. Should I be getting the same from post('my_name')?
Aleksey Bobkov
Tuesday, August 30, 2011@Silas Bondrup-Nielsen post() function should be suitable for you. This function is a wrapper for the $_POST array and works similarly. The only difference between post() and $_POST is that post() can return a default value if the key is not found in $_POST.
Add your comment
Loading form...