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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀