1

ページ上部のフォームを使用してフィルタリングできる「レポート」を作成しようとしています。結果をフィルタリングするオプションは、デフォルトで現在の会計年度である会計年度と、すべてデフォルトでチェックされている複数のカテゴリ(チェックボックス)です。ページはデフォルトのデータで適切に生成されますが、フォームが送信されると、ページは「更新」されますが、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 -->

ここから、元のコードは結果をテーブルに出力し続けますが、これは正しく機能し、問題ではないと思います。頼まれればもっと共有できます。

4

3 に答える 3

1

チェックしたい場合は、送信ボタンに名前を付ける必要があります

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

そうしないと、php はそれを $_POST 配列に配置しません。

于 2012-06-19T20:13:21.560 に答える
1

_POST 値があるかどうかのチェックが間違っていると思います。これを試して:

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

そして、それが機能するかどうかを確認します

于 2012-06-19T20:07:13.590 に答える
1

フォームが送信されたかどうかを確認するために使用している場合は、送信ボタンに名前を付ける必要があります...

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

または、送信ボタンを変更したくない場合は、代わりにカテゴリ入力で isset をチェックできます

if(isset($_POST['Category'])){echo"SET";} else{echo"NOT SET";}
于 2012-06-19T20:14:24.107 に答える