简体   繁体   English

foreach和输入类型在php中提交?

[英]foreach and input type submit in php?

My problem is the buttons don't work, the only thing that happens is that it reloads the page. 我的问题是按钮不起作用,唯一发生的是它重新加载了页面。 And is there anyone that know how to make new buttons instant after I create them in my database? 在我在数据库中创建新按钮之后,是否有人知道如何立即创建新按钮?

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" class="index_head" id = "login_form" >
<?php 
        header('Cache-Control: no-cache');
        header('Pragma: no-cache');
        require "gettops.php";
        $tops = getTops();
        if(!empty($tops))
        foreach ($tops as $top) {

        if(isset($_POST[$top[0]]) && !empty($_POST[$top[0]]))
        {
            header("location:forgot_checkin.php");
        }

        ?>  
            <input type="submit" Name="print" value="<?php echo $top[0]; ?>" class="btn btn-large btn-primary" />

     <?php } //end foreach ?>   

<input type="submit" Name="print" value="Download Excel" class="btn btn-large btn-primary">
<input type="submit" Name="print" value="Download Excel" class="btn btn-large btn-primary">
</form>

Your form is not submitting anywhere: $_SERVER['PHP_SELF'] is equivalent to "#" or "" . 您的表单不在任何地方提交: $_SERVER['PHP_SELF']等效于"#""" You should include the place the form should submit to and avoid $_SERVER['PHP_SELF'] . 您应该包括表单应提交到的位置,并避免$_SERVER['PHP_SELF'] Most of these SERVER_VARS are depreciated anyway. 无论如何,这些SERVER_VARS中的大多数已折旧。

I'm not entirely sure on your question vs. the code that is present for creating new buttons, but you can do: 对于创建新按钮时出现的代码,我不确定您的问题,但您可以执行以下操作:

<? foreach ($query as $row) { ?>
    <a href="<? echo $row['link']; ?>"><input type="button" Name="print" value="<?php echo $row['button']; ?>" class="btn btn-large btn-primary" /></a>
<? } ?>

You can of course make the button line an echo and never leave php mode. 您当然可以使按钮行回显,并且永远不会离开php模式。 But are there multiple buttons just redirecting? 但是是否有多个按钮只是重定向? Or do they submit the form to multiple places? 还是他们将表单提交到多个地方? If they just link you don't even need a form an can append <a href="#"></a> around your button or append onclick="#" to the button tag (or nicer: using jQuery('').click({});. 如果他们只是链接,您甚至不需要表单,就可以在按钮周围添加<a href="#"></a>或将onclick="#"附加到按钮标签(或者更好:使用jQuery('' ).click({});。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM