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

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.

我遇到的问题涉及使用PHP echo语句生成的HTML输入。 这是我输出表格的函数: code> p>

  function confirm_recipients()
 {
 
 echo“&lt; form  action =''name ='email_options'method ='post'&gt;“; 
 echo”&lt; input type ='submit'name ='sendRecipients'value ='是的,我想发送电子邮件'&gt;“  ; 
 echo“&lt; / form&gt;”; 
} 
  code>  pre> 
 
 

p>

稍后在同一个PHP页面中 ,我调用该函数,然后检查是否设置了提交按钮。 p>

confirm_recipients(); code> p> if(isset($ _ POST ['sendRecipients'])) { //执行动作 } code> pre>

p >

但是,即使设置了提交按钮(由用户点击),此代码也不起作用,if语句块永远不会执行。 从我想要“读入”的同一文件中发帖可能存在问题? 感谢您的任何建议。 p>

更新 p>

感谢您立即回复。 遗憾的是,没有任何建议有效(删除了动作值中的空格或user623952提出的建议)。 没有报告任何错误,按钮只是无法设置。 我正在寻找文件中可能有错误的其他地方,也许按我调用函数的顺序。 p> div>

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. It's okay to POST the form data to the same script that contains the form. Change the action attribute to the URL of the script, do not set it to whitespace, which is what you did.

  2. I don't think the value of a submit input is sent as part of the POST. Try using an input type="hidden" with the name 'sendRecipients'.