php - Initialize variables that are not called from POST -
i learning how code php , have 2 pages: rates.html , rates.php. our assignment has need run rates.php , no longer need use rates.html. way of going around problem follows:
if (empty($_post['txtinput'])){ $inputcurrency = 0; $outputcurrency = 0; $txtinput = ''; } else { $inputcurrency = $_post['inputcurrency']; $outputcurrency = $_post['outputcurrency']; $txtinput = $_post['txtinput']; }
input , output currencies made in form of drop down list, , txtinput number user wants convert.
the problem page throws error message when user submits form without input in field. page loads following code:
if ( empty($txtinput) ) { $error_message = 'input required field.'; } else if ( !is_numeric($txtinput) ) { $error_message = 'input must valid number.'; } else if ( $txtinput <= 0 ) { $error_message = 'input must greater zero.'; } else { $error_message = ''; }
is there way flag not thrown on pages first load? appreciated
wrap logic should run when form submitted in if block checks see if form submitted via post:
if ('post' === $_server['request_method']) { // form submitted. put form logic here. }
Comments
Post a Comment