嗨大家对表单有什么问题....当发布到网站时我得到这个错误(注意:未定义索引:),它的工作原理只是错误高于实际形式,单挑出下面表格的顶部它说错误在哪里......
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("myemail@email.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
答案 0 :(得分:1)
<?
if(isset($_REQUEST['action']) && $_REQUEST['action']!="")
{
//do stuff
}
else
{
?>
<!-- show form --->
<?php
}
?>
答案 1 :(得分:0)
通知出现原因未找到值或未初始化变量。所以尝试初始化变量或使用检查值
$action=(isset($_REQUEST['action']) ? $_REQUEST['action'] :'');
if(!empty($action))
// do your stuff
答案 2 :(得分:0)
检查$ _REQUEST中是否设置了索引action
。并使用empty()
检查其设置是否为空。
答案 3 :(得分:0)
您正在以错误的方式检查表单提交
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
假设,控件来自的按钮名称为name="submit_form"
,方法为POST
使用:
if(isset($_POST["submit_form"])) //this will check if "submit_form" was pressed or not
{
//show form submission action
}
else
{
//don't show show form submission action
}
答案 4 :(得分:0)
用这个改变你的代码...... 你应该在php中使用空函数来检查variabel是否为空。因为$ _REQUEST [&#39; action&#39;]中的索引操作在第一个代码运行时永远不存在。
<?php
$action = (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : "";
if ($action==""): /* display the contact form */
?>
<?php
$action= (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : "";
if ($action==""): /* display the contact form */
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
endif;
else: /* send the submitted data */
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("aridjemana@email.com", $subject, $message, $from);
echo "Email sent!";
}
endif;
?>