doupao2277 2013-11-18 05:03
浏览 38
已采纳

PHP生成表单的输入未被记录

The issue I have been experiencing deals with input from HTML which was generated using PHP echo statements. Here is the function I have that outputs the form:

function confirm_recipients()
    {

        echo "<form action = ' ' name ='email_options' method='post'>";
        echo "<input type='submit' name='sendRecipients' value='Yes, I want to send the emails' >";
        echo "</form>";
    }

Later on in the same PHP page, I call the function and then check to see if the submit button was set.

confirm_recipients();

if (isset($_POST['sendRecipients'])) 
    {
    //perform actions
    }

However, this code is not functional seeing as even when the submit button is set (clicked by the user), the if statement block is never executed. Perhaps there is an issue with posting from the same file I want to "read in" from? Thanks for any advice.

Updates

Thank you for such immediate response. Sadly none of the suggestions have worked (removing the space in the action value or the suggestion made by user623952). No errors have been reported, the button is just failing to be set. I am looking for other places in the file that might have errors, perhaps in the order I call the function.

  • 写回答

2条回答 默认 最新

  • dongya2578 2013-11-18 05:16
    关注

    This works fine for me:

    <?php
    
    print "<pre>".print_r($_POST,true)."</pre>"; 
    
    confirm_recipients();
    
    function confirm_recipients() { 
        echo "<form action = ' ' name ='email_options' method='post'>";
        echo "<input type='submit' name='sendRecipients' value='Yes, I want to send the emails' >";
        echo "</form>";
    }
    
    
    if (isset($_POST['sendRecipients']))
    {
        print "<br/>sendRecipients is set!<br/>"; 
    }
    
    ?>
    

    I think your problem might be somewhere else in the code.

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

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应