【问题标题】:(PHP) Can't get value from input HTML. Any wrong code? [duplicate](PHP) 无法从输入的 HTML 中获取值。有错误的代码吗? [复制]
【发布时间】:2017-04-13 17:59:25
【问题描述】:

我在我的网站上使用 wordpress。然后我创建了一个发送包含批评和建议的电子邮件的表单。消息已发送,但我无法从输入中获取评论/建议值。

<?php    
$myemail = '';//<-----Put Your email address here.
$email = $_POST['email'];
$comment = $_POST['message'];

if(isset($_REQUEST['submit']))
{
$to = $myemail;
$email_body = "Ada kritik dan saran dari seseorang!.\n".
"Pengirim: $email \n".
"Pesan:\n $comment";
mail($to,"Kritik dan Saran",$email_body);}

add_filter ('the_content', 'guerrilla_add_post_content', 0);
function guerrilla_add_post_content($content) {
    if (is_single()) { 
        $content .= '
            <div class="guerrillawrap">
  <h5 style="
    margin-bottom: 20px;
    margin-top: 0;
">Bantu tingkatkan kualitas review dan artikel TerasGame dengan mengirimkan Kritik &amp; Saran</h5>
  <form method="POST" action="" name="contact_form" enctype="text/plain">
<input type="text" name="email" style="
    width: 29%;
" placeholder="E-mail Kamu" value=""><input type="text" name="message" value="" style="
    width: 70%;
    /* text-align: center; */
    float: right;
" placeholder="Tulis Kritik dan Saranmu di sini..."> 
<input type="submit" name="submit" style="
    width: 100%;
    margin-top: 10px;
    text-align: center;
    float: right;
">

  </form>
<p></p></div>
        ';
    }
    return $content;
}

?>

我尝试了很多方法,并且我从表单中发送了很多电子邮件,但它们都是一样的,没有消息和电子邮件输入值。谢谢。

【问题讨论】:

    标签: php


    【解决方案1】:

    删除 enctype="text/plain.and 并创建您的 html 代码正确格式。

    <body>
    
            <div class="guerrillawrap">
                <h5 style="margin-bottom: 20px;margin-top: 0;">Bantu tingkatkan kualitas review dan artikel TerasGame dengan mengirimkan Kritik &amp; Saran</h5>
                <form method="POST" action="example.php" name="contact_form">
                    <input type="text" name="email" style="width: 29%;" placeholder="E-mail Kamu">
                    <input type="text" name="message" style="width: 70%;float: right;" placeholder="Tulis Kritik dan Saranmu di sini..."> 
                    <input type="submit" name="submit" style="width: 100%;margin-top: 10px;text-align: center;float: right;">
    
                </form>
                <p></p></div>
    
        </body>

    【讨论】:

    • 谢谢你,它真的有效!对不起我丑陋的代码兄弟:)
    • 不客气 :)
    【解决方案2】:

    删除enctype="text/plain",这样就可以了

    <form method="POST" action="" name="contact_form">
    

    您使用了一种不起作用的编码类型。详情见:http://www.w3schools.com/tags/att_form_enctype.asp

    【讨论】:

    • 哇!感谢那!有用!对不起我丑陋的代码:)
    猜你喜欢
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2019-09-06
    • 2013-10-15
    相关资源
    最近更新 更多