PHP没有从文本框中获取文本 [英] PHP Not getting text from textbox
问题描述
PHP代码。
//两条电子邮件行
$ email_to =contact@mywebsite.com;
$ email_subject =AUTO:REQUEST;
//设置等于电子邮件表单文本框
$ email_form = $ _POST ['email_text'];
$ email_message =电子邮件:。 $ email_form。 ;
//创建电子邮件标题
@mail($ email_to,$ email_subject,$ email_message,$ headers);
表单的HTML代码
< div id =form>
< form method =postaction =Email_Form_Script.phpenctype =text / plainonsubmit =window.open('FormPopUp.html','popup','width = 500,高度= 500,滚动条=无,可调整大小=没有,工具栏=没有,目录=没有,位置=没有,菜单栏=没有,状态=无,左= 0,顶部= 0' ); >
< div>
< input type =textclass =textname =e3textid =emailFormvalue =输入您的电子邮件地址onfocus =if(this.value =='Enter your电子邮件地址'){this.value =''}onblur =if(this.value ==''){this.value ='输入您的电子邮件地址'}/>
< input type =hiddenvalue =name =email2/>
< input type =hiddenname =locvalue =en_US/>
< input type =submitclass =submitvalue =/>< / div>
< / form>
< / div>
真的很困惑,为什么它不起作用。我一直在收到只是说电子邮件:(电子邮件后没有文字)的空电子邮件。 解决方案
t实际上包含一个名为 email_text
的输入元素,它在您的PHP代码中被引用。您需要将您的HTML表单代码构建为至少如下所示,或者将PHP代码更改为需要 $ _ POST ['e3text']
。
< div id =form>
< form method =postaction =Email_Form_Script.phpenctype =text / plainonsubmit =window.open('FormPopUp.html','popup','width = 500,height = 500,滚动条=无,可调整大小=没有,工具栏=没有,目录=没有,位置=没有,菜单栏=没有,状态=无,左= 0,顶部= 0' ); >
< div>
< input type =textclass =textname =email_textid =emailFormvalue =输入您的电子邮件地址onfocus =if(this.value =='Enter your电子邮件地址'){this.value =''}onblur =if(this.value ==''){this.value ='输入您的电子邮件地址'}/>
< input type =hiddenvalue =name =email2/>
< input type =hiddenname =locvalue =en_US/>< input type =submitclass =submitvalue =/>
< / div>
< / form>
< / div>
Whenever I enter text into the textbox, it is not properly transferring to PHP. PHP reads the input as null, when in reality, there is text in there.
PHP code.
//Two Email Lines
$email_to = "contact@mywebsite.com";
$email_subject = "AUTO: REQUEST";
//Set equal to email form textbox
$email_form = $_POST['email_text'];
$email_message = "Email: " . $email_form . "";
//Create email headers
@mail($email_to, $email_subject,$email_message,$headers);
HTML code for the form
<div id="form">
<form method="post" action="Email_Form_Script.php" enctype="text/plain" onsubmit="window.open('FormPopUp.html','popup','width=500,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');" >
<div>
<input type="text" class="text" name="e3text" id="emailForm" value="Enter your e-mail address" onfocus="if(this.value=='Enter your e-mail address') { this.value = '' }" onblur="if(this.value=='') { this.value = 'Enter your e-mail address' }" />
<input type="hidden" value="" name="email2"/>
<input type="hidden" name="loc" value="en_US"/>
<input type="submit" class="submit" value=""/></div>
</form>
</div>
Really confused as to why it is not working. I keep getting empty emails that just say " Email: " (No text after Email).
Its because your form doesn't actually contain an input element named email_text
which is referenced in your PHP code. You need to structure your HTML form code to at least look like this or change your PHP code to require $_POST['e3text']
.
<div id="form">
<form method="post" action="Email_Form_Script.php" enctype="text/plain" onsubmit="window.open('FormPopUp.html','popup','width=500,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');" >
<div>
<input type="text" class="text" name="email_text" id="emailForm" value="Enter your e-mail address" onfocus="if(this.value=='Enter your e-mail address') { this.value = '' }" onblur="if(this.value=='') { this.value = 'Enter your e-mail address' }" />
<input type="hidden" value="" name="email2"/>
<input type="hidden" name="loc" value="en_US"/><input type="submit" class="submit" value="" />
</div>
</form>
</div>
这篇关于PHP没有从文本框中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!