Very short snippet: PHP isset_post ()

Often having to check if a variable has been sent with the POST, and if not, assign a default value. Instead of using the syntax:

1
isset ( $_POST [ 'var_post' ] ) ? $_POST [ 'var_post' ] : default ; $ Miavar = isset ($ _POST ['var_post'])? $ _POST ['var_post']: default;

might use a service function as:

1
2
3
4
5
6
7
8
9
10
/ **
* Check if a POST variable is present, otherwise
* Sets a default value
*
* @ Param $ id_post ID of the variable POST
* @ Param $ default (optional) value to be assigned to the variable if not set
* /
$id_post , $default = '' ) { isset_post function (id_post $, $ default ='') {
isset ( $_POST [ $id_post ] ) ? $_POST [ $id_post ] : $default ) ; return ( isset ($ _POST [$ id_post])? $ _POST [$ id_post]: $ default);
}

So as to obtain:

1
2
3
isset_post ( 'var_post' ) ; Miavar isset_post = $ ('var_post');
/ / Or
isset_post ( 'var_post' , 'valore di default' ) ; Miavar isset_post = $ ('var_post', 'default');

There are no comments for this post

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA