出于某种原因,点击提交后,我的页面只会重定向回一个清空的表单。我似乎无法弄清楚原因。我唯一的猜测是它没有认识到"提交"是真的,只是通过else子句返回自己。但是,我已将表单的操作切换为已定义的URL(例如http://google.com)并将其发送给目标。非常感谢任何帮助。
编辑:我已经能够可靠地显示我的表单标签的动作值是不正常的。
我执行了以下测试:我可以输入if / else语句的任一条件,并使该值在条件下回显。但是,如果我尝试在表单上方回显它,它不会返回任何内容,但我输入表单的值将在表单上方回显(例如,conferenceName为$ _POST [' conferenceName']将在表格之上回应。
<!DOCTYPE html>
<html>
<head>
<title>Conference Registration [This Page Not Yet Active]</title>
<link rel="stylesheet" type="text/css" href="cmxform.css">
</head>
<body>
<form method="post" action="<?php echo $action; ?>" class="cmxform">
<fieldset>
<legend>Example Conference Registration</legend>
<ol style="list-style-type: none;">
<li>
<label for="conferenceName">Applicant's Name<em>*</em></label> <input name="conferenceName" type="text">
</li>
<li>
<label for="conferenceAgencySchool">Agency School<em>*</em></label> <input name="conferenceAgencySchool" type="text">
</li>
<li>
<label for="conferenceAgencyAddress">Agency Address<em>*</em></label> <input name="conferencePhysicalAddress" type="text">
</li>
<li>
<label for="conferenceCity">City<em>*</em></label> <input name="conferenceCity" type="text">
</li>
<li>
<label for="conferenceState">State<em>*</em></label> <input name="conferenceState" type="text">
</li>
<li>
<label for="conferenceZip">Zip<em>*</em></label> <input name="conferenceZip" type="text">
</li>
<li>
<label for="conferencePhone">Phone<em>*</em></label> <input name="conferencePhone" type="text">
</li>
<li>
<label for="conferenceExtension">Extension</label> <input name="conferenceExtension" type="text">
</li>
<li>
<label for="conferenceNumberOfAttendees">Number of Attendees<em>*</em></label> <input name="conferenceNumberOfAttendees" type="text">
</li>
<li>
<label for="conferencePointOfContactName">P.o.C. Name<em>*</em></label> <input name="conferencePointOfContactName" type="text">
</li>
<li>
<label for="conferencePointOfContactPhone">P.o.C. Cell Phone<em>*</em></label> <input name="conferencePointOfContactPhone" type="text">
</li>
<li>
<label for="conferencePointOfContactEmail">P.o.C. Email<em>*</em></label> <input name="conferencePointOfContactEmail" type="text">
</li>
<li>
<label for="conferenceAdditionalAttendeeInfo">Additional Attendee(s) Info</label>
<textarea name="conferenceAdditionalAttendeeInfo" style="height: 100px; width: 90%; max-width: 90%; min-width: 90%;" wrap="soft"></textarea>
</li>
</ol>
<hr>
<legend>Method of Payment<em>*</em></legend>
<ol style="list-style-type: none;">
<li>
<label><input name="payment" type="radio" value="Online">Online</label>
</li>
<li>
<label><input name="payment" type="radio" value="At The Door"> At the Door</label>
</li>
<li>
<label>Invoice # (If Using Invoice)</label><input name="invoiceNumber" type="text">
</li>
</ol>
<hr>
</fieldset><input name="submit" type="submit" value="Submit Application">
</form>
<?php
if (isset($_POST["submit"]) &&
(!empty($_POST["conferenceName"])) &&
(!empty($_POST["conferenceAgencySchool"])) &&
(!empty($_POST["conferencePhysicalAddress"])) &&
(!empty($_POST["conferenceCity"])) &&
(!empty($_POST["conferenceState"])) &&
(!empty($_POST["conferenceZip"])) &&
(!empty($_POST["conferencePhone"])) &&
(!empty($_POST["conferenceNumberOfAttendees"])) &&
(!empty($_POST["conferencePointOfContactName"])) &&
(!empty($_POST["conferencePointOfContactPhone"])) &&
(!empty($_POST["conferencePointOfContactEmail"]))
)
{
$action="http://example.net/form-submit.php";
}
else
{
$action = '"<?php echo $_SERVER["PHP_SELF"]; ?>"';
}
?>
</body>
</html>
按照您所提供的建议后的输出。
<!DOCTYPE html>
<!-- saved from url=(0044)http://example.net/conference-registration.php -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Conference Registration [This Page Not Yet Active]</title>
<link rel="stylesheet" type="text/css" href="./Conference Registration [This Page Not Yet Active]_files/cmxform.css">
</head>
<body>
<form method="post" action="" class="cmxform">
<fieldset>
<legend>Example Conference Registration</legend>
<ol style="list-style-type: none;">
<li>
<label for="conferenceName">Applicant's Name<em>*</em></label> <input name="conferenceName" type="text">
</li>
<li>
<label for="conferenceAgencySchool">Agency School<em>*</em></label> <input name="conferenceAgencySchool" type="text">
</li>
<li>
<label for="conferenceAgencyAddress">Agency Address<em>*</em></label> <input name="conferencePhysicalAddress" type="text">
</li>
<li>
<label for="conferenceCity">City<em>*</em></label> <input name="conferenceCity" type="text">
</li>
<li>
<label for="conferenceState">State<em>*</em></label> <input name="conferenceState" type="text">
</li>
<li>
<label for="conferenceZip">Zip<em>*</em></label> <input name="conferenceZip" type="text">
</li>
<li>
<label for="conferencePhone">Phone<em>*</em></label> <input name="conferencePhone" type="text">
</li>
<li>
<label for="conferenceExtension">Extension</label> <input name="conferenceExtension" type="text">
</li>
<li>
<label for="conferenceNumberOfAttendees">Number of Attendees<em>*</em></label> <input name="conferenceNumberOfAttendees" type="text">
</li>
<li>
<label for="conferencePointOfContactName">P.o.C. Name<em>*</em></label> <input name="conferencePointOfContactName" type="text">
</li>
<li>
<label for="conferencePointOfContactPhone">P.o.C. Cell Phone<em>*</em></label> <input name="conferencePointOfContactPhone" type="text">
</li>
<li>
<label for="conferencePointOfContactEmail">P.o.C. Email<em>*</em></label> <input name="conferencePointOfContactEmail" type="text">
</li>
<li>
<label for="conferenceAdditionalAttendeeInfo">Additional Attendee(s) Info</label>
<textarea name="conferenceAdditionalAttendeeInfo" style="height: 100px; width: 90%; max-width: 90%; min-width: 90%;" wrap="soft"></textarea>
</li>
</ol>
<hr>
<legend>Method of Payment<em>*</em></legend>
<ol style="list-style-type: none;">
<li>
<label><input name="payment" type="radio" value="Online">Online</label>
</li>
<li>
<label><input name="payment" type="radio" value="At The Door"> At the Door</label>
</li>
<li>
<label>Invoice # (If Using Invoice)</label><input name="invoiceNumber" type="text">
</li>
</ol>
<hr>
</fieldset><input name="submit" type="submit" value="Submit Application">
</form>
<script type="text/javascript" async="" src="./Conference Registration [This Page Not Yet Active]_files/si.js"></script></body></html>
答案 0 :(得分:1)
您将PHP回显包含在引号中,这是在以下行中执行的错误方法:
$action = '"<?php echo $_SERVER["PHP_SELF"]; ?>"';
此代码仅返回""
。
将其更改为
$action = $_SERVER["PHP_SELF"];
答案 1 :(得分:0)
您可以在操作变量中使用“#”或分配$ _SERVER [“PHP_SELF”]。