簡體   English   中英

表單到PHP_SELF但不傳遞post值

[英]Form to PHP_SELF but does not pass post values

我正在嘗試創建一個“報告”,可以使用頁面頂部的表單進行過濾。 篩選結果的選項是財政年度,默認情況下是當前的FY,默認情況下都會檢查多個類別(復選框)。 頁面使用默認數據正確生成,但是在提交表單時,頁面將“刷新”但沒有生成POST數據。 我嘗試創建頁面副本並將其設置為操作URL但它仍然沒有任何POST數據並使用默認值。 我將在下面包含我的代碼,並嘗試將其縮小到只需要的部分,以使其更容易,但如果需要可以共享所有部分。 提前感謝您提供的任何幫助。

<body>
    <?php 
    if(isset($_POST['submit'])){echo"SET";} else{echo"NOT SET";}
// Establish Connection and Variables       
// Connection   
        include "./include/class/DBConnection.php";
        DBConnection::$dsn;
        DBConnection::$user;
        DBConnection::$pass;
        DBConnection::getDBConnection();
// The Current Fiscal Year
        $today = getdate();
        $month = $today['month'];
        // seperate first and second half of fiscal year
        $old = array('January','February','March','April','May','June');    
        if (in_array($month,$old)) {
            $year = $today['year'] + 1;
        }
        else {
            $year = $today['year'];
        }                       
// Create SQL Query Variables - Removed for post
// Set filter criteria
// Retrieve array of possible categories and create SQL WHERE statment  
        $catAllCxn = DBConnection::$cxn->prepare($SQL_Categories);
        $catAllCxn->execute();
        $catAllCxn->setFetchMode(PDO::FETCH_ASSOC);
        $catAllArray = array();
        while($catAllRow = $catAllCxn->fetch()) {
            $cat = $catAllRow['Category'];
            array_push($catAllArray, $cat);
        }
        $catAllInQuery = implode(',',array_fill(0,count($catAllArray),'?'));
// Create array for category filter IF form was submitted to itself
        if (isset($_POST['submit'])){  // if page is submitted to itself

            $catFilterArray = $_POST['Category'];
            $catFilterInQuery = implode(',',array_fill(0,count($catFilterArray),'?'));

        }
// Switch for ALL or Filtered report
        if(!isset($_POST['submit'])) { // if page is not submitted to itself 

            $FiscalYear = $year;
        //  $DiscludedDepartmentNumbers = "21117";
            $catArray = $catAllArray;
            $IncludedCategories = $catAllInQuery;
        }
        else {
            $FiscalYear = $_POST["FiscalYear"];
        //  $DiscludedDepartmentNumbers = "21117";
            $catArray = $catFilterArray;
            $IncludedCategories = $catFilterInQuery;
        }               
    ?>
<!-- Filter Form -->        
    <div id="filters" style="border: 1px solid;"> 
        <form name="filter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST"> 
            Fiscal Year: <input type="text" name="FiscalYear" value="<?php echo $FiscalYear; ?>" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php if(isset($_POST['submit'])){echo"SET";} else{echo"NOT SET";}?>
            <br />
            <fieldset>
                <legend>Select Categories</legend>
                <?php 
                    foreach($catAllArray as $catAllRow) {
                        if (!isset($_POST['submit'])) {
                            echo "<input type=\"checkbox\" name=\"Category\" value=\"".$catAllRow."\" checked=\"checked\" />".$catAllRow."&nbsp;&nbsp;\n";
                        }   
                        else if(in_array($catAllRow,$catArray)) {
                            echo "<input type=\"checkbox\" name=\"Category\" value=\"".$catAllRow."\" checked=\"checked\" />".$catAllRow."&nbsp;&nbsp;\n";
                        }
                        else {
                            echo "<input type=\"checkbox\" name=\"Category\" value=\"".$catAllRow."\" />".$catAllRow."&nbsp;&nbsp;\n";
                        }   
                    }   
                ?>
            </fieldset> <br />
            <input type="submit" value="submit" />
        </form> <!-- End: filter -->
    </div>  <!-- End: filters -->

從這里開始,原始代碼繼續將結果輸出到表中,但這種方法正常,我不認為這是問題所在。 如果被問到,我可以分享更多。

我認為你檢查是否有_POST值是錯誤的。 嘗試這個:

if(isset($_POST['FiscalYear']))

看看是否有效

如果要檢查它,您需要命名您的提交按鈕

<input type="submit" value="submit" name="submit" />

否則php不會將它放在$ _POST數組中

您需要為提交按鈕指定一個名稱,如果您正在使用它來檢查表單是否已提交...

<input type="submit" value="submit" name="submit" />

或者,如果您不想更改提交按鈕,則可以檢查類別輸入上的isset

if(isset($_POST['Category'])){echo"SET";} else{echo"NOT SET";}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM