Home >Backend Development >PHP Tutorial >Simple calculation function, simple calculation function_PHP tutorial
Rendering
To make the above rendering, we need to have a simple understanding of the elements of the hidden form
The syntax format of hidden form elements is: 549d29993e26ac6470e75c2d3076b69b. Its function is to prevent the browser from displaying this form field element when browsing the web page, but will display this form field element when submitting the form. Hide the name attribute of form elements
and the value attribute value are sent to the server
<?<span>php </span><span>$CFQ</span> = <span>$_POST</span>["tag"];<span>//</span><span>判断用户是否单击了计算按钮</span> <span>if</span>(<span>$CFQ</span> == 1<span>) { </span><span>$addnum1</span> = <span>$_POST</span>["addnum1"];<span>//</span><span>通过$_POST内置数组获取加数</span> <span>$addnum2</span> = <span>$_POST</span>["addnum2"<span>]; } </span><span>else</span><span>{ </span><span>$addnum1</span> = <span>$addnum2</span> = 0<span>; } </span><span>$sum</span> = <span>$addnum1</span> + <span>$addnum2</span><span>; </span>?><span> 在表单中输入两个整数 </span><form name = "form1" method = "post" action = "#"> <input type = "hidden" name = "tag" size = "4" value="1"> <!--值用于做相等判断--> <input type="text" name="addnum1" size="4" value="<?php echo <span>$addnum1</span>;?>"> + <input type="text" name="addnum2" size="4" value="<?php echo <span>$addnum2</span>;?>"> = <?php <span>echo</span> <span>$sum</span>;?><br> <!--输出计算结果--> <br><input type="submit" name="Submit" value="计算"> <input type="reset" name="Submit" value="重置"> </form>