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