douya5194 2014-04-12 12:35
浏览 125
已采纳

PHP:清除/重置表单,提交给自己

newb here.

Site url: http://school.max-o-matic.com/itc250.php#011

My student portal has two assignments on it which i've completed, both are forms and I'd like to be able to reset/clear them. I know that i could create a button to clear them that sends the user from 'http://school.max-o-matic.com/itc250.php#011' to 'http://school.max-o-matic.com/itc250.php' which would remove the anchor tag and that would reload the page clearing/resetting the forms in the process. But it would also require scrolling. I could also create a second anchor tag ('#011b') and have that in an invisible element and reload the page to that to keep/prevent scrolling but that seems like cheating/a dirty hack to me vs good programmatic practice.

I attempted to use this to reset the form ('echo '') but it doesn't seem to do anything. So i'm hoping someone can help me to find a good method to achieve my end goal which is to have a repeatable tool that will clear/reset the page so i can test out multiple scenarios without needing to scroll/rescroll continuously.

<?php

    //Constant never changes, 100% available everywhere- almost always simple datatypes (T or F, num, string)
    //define('THIS_PAGE', $_SERVER['PHP_SELF']);//shows webroot
    define('THIS_PAGE', basename($_SERVER['PHP_SELF']));//shows app root - gets name of the file basically

    define('TAX_RATE', .095); //current tax rate us => .095 => is 9.5%

    //echo THIS_PAGE;// shows this pagefile
    //VAR_DUMP - we love it cause we can see everything


    if (isset($_POST['submit'])) {//if data, do processing

        $purch01 = (float) $_POST['purchase01'];//float before floats data after
        $purch02 = (float) $_POST['purchase02'];//float before floats data after

        $subtotal = $purch01 + $purch02;

        $amountTax = TAX_RATE * $subtotal;

        $amountTotal = $amountTax + $subtotal;

        echo "<br /><br />";

        echo 'First Purchase: $' . round($purch01, 2) . '<br />';//standard
        echo 'First Purchase: $' . round($purch02, 2) . '<br />';//standard
        echo '<hr />';

        echo 'Subtotal before tax: $' . round($subtotal, 2) . '<br />';//standard
        echo 'Tax: $' . round($amountTax, 2) . '<br />';//standard
        echo '<hr />';

        echo 'Washington state tax: %' . TAX_RATE . '<br />';
        echo '<hr />';

        echo 'your purchase amount is $' . round($amountTotal, 2) . '<br /><br />';//risky double dollar sign


        /*
        echo '<pre>';
            var_dump($_POST); //shows everything the post knows
        echo '</pre>';
        */
        echo '<input type="reset" "reset the form." /><br /><br /><hr />';


    }else{//show Output

        echo
        '
            <form method="post" action="itc250.php#011">

                Enter Purchase Amount:
                <input type="text" name="purchase01" />
                <br />
                <br />

                Enter Purchase Amount:
                <input type="text" name="purchase02" />
                <br />

                <input type="submit" name="submit" />
        ';

    }//if you dont' need else, do a 'print and die statement' so if else happens you know else happened.

?>
  • 写回答

3条回答 默认 最新

  • doujiena0025 2014-04-12 21:11
    关注

    I found a solution which is as follows:

    In the head I added:

    <script> function reloadPage() { location.reload(); } </script>
    

    In the body I added:

    <input type="button" value="Reload page" onclick="reloadPage()">
    

    This does what I want and it's something I can neatly apply over and over again so that's cool.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示