douren6874 2015-07-08 19:43
浏览 46
已采纳

使用选项卡式索引页面中的表单

So I'm new to PHP and I'm having trouble getting some of my forms to function. I think it may be the way my site is set up that's causing me problems.

I have index.php which is set up as such:

<div class="pageContent">
<div id="main" style="width:1000px; margin:0 auto;">
    <!-- Create the tabs -->
    <div id="tabs" >
        <ul>
            <li><a href="#tabs-0">Overview</a></li>      
            <li><a href="#tabs-1">Ranked</a></li>
            <li><a href="#tabs-2">Arena</a></li>
            <li><a href="#tabs-3">Decks</a></li>
            <li><a href="#tabs-4">New Game</a></li>     
            <li><a href="#tabs-5">Admin</a></li>

        </ul>
        <div id="tabs-0"></div>
        <div id="tabs-1"></div>
        <div id="tabs-2"></div>
        <div id="tabs-3"></div>
        <div id="tabs-4"></div> 
        <div id="tabs-5"></div>
    </div>
    <!-- Load the pages into tabs -->
    <script>
        $("#tabs").tabs();
        $("#tabs-0").load("tab0.php");
        $("#tabs-1").load("tab1.php");
        $("#tabs-2").load("tab2.php");
        $("#tabs-3").load("tab3.php");
        $("#tabs-4").load("newGame.php");
        $("#tabs-5").load("admin.php");
    </script>
</div><!-- / main -->
</div><!-- / pageContent -->

This gives me a nice static page and 6 tabs of .php files to do cool stuff on.

There are a couple of forms, log in and such, in index.php which all function fine. But when I create a form on a page in a tab, it will not.

Here's an example from admin.php (#tabs-5)

<?php
if(isset($_POST['delLog'])){
    unlink('log.txt');
    echo 'Success';
}
if(isset($_POST['delLog'])){
    unlink('error_log');
    echo 'Success';
}
?>
<html>
<head>
</head>
<body>
<table width="100%" border="1">
  <tr>
    <td width="40%" valign="top"> 
    </td>
    <td width="30%" valign="top">
    <h1>error_log</h1>
        <form action="" method="post">
        <input type="submit" name="delErr" id="delErr" value="Delete" />
        </form>
        <hr />
    <?php       
        $lines = explode("
", file_get_contents('error_log'));
        foreach ($lines as $line){
            echo $line.'<br>';
        }
    ?>
    </td>
    <td width="3'0%" valign="top">
    <h1>log.txt</h1>
    <form action="" method="post">
    <input type="submit" name="delLog" id="delLog" value="Delete" />
    </form>
    <hr />
    <?php   
        $lines = explode("
", file_get_contents('log.txt'));
        foreach ($lines as $line){
            echo $line.'<br>';
        }
    ?>
     </td>
  </tr>
</table>
</body>
</html>

This is another, better example. A stripped down test I did yesterday for this question

Problems with $_POST

<?php
    define('INCLUDE_CHECK',true);
    include 'php/functions.php';

    error_reporting(E_ALL); 
    ini_set('display_errors',1);

    logThis('ready!');  

    if (isset($_POST['submit'])) {       
        logThis('success'); 
    }
?>
<html>
<head>

</head>
<body>
    <form method="post" action="">
        <input type="submit" name="submit" id="submit" value="Submit" />
    </form>
</body>
</html>

Neither of these examples work. When the submit button is pressed the site refreshes but no PHP actions are taking place. There is no error message in error_log. I don't think it's getting the call at all.

Neither of the forms return an output, one adds to the database. The other deletes log files.

Hope I've provided enough details.

  • 写回答

2条回答 默认 最新

  • dtnbjjq51949 2015-07-08 19:59
    关注

    What ever you are trying to do is not possible at all. You can not load PHP code to frontend, it can only be processed by the server.

    The statement $("#tabs-5").load("admin.php"); is fetching only the html code (processed by the server) not the PHP script

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

报告相同问题?

悬赏问题

  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改