所以这是一个基本的表单提交和处理,骨子里。有三个脚本,表单脚本,处理器脚本和视图页面。下面是摘录从每个:使用PHP处理表单数据
形式:
<form action="processor.php" method="post">
<h4>Question # 1</h4>
<p>What grade are you in?</p>
<label class="checkbox"><input type="checkbox" name="grade" value="1"> Freshmen</label>
<label class="checkbox"><input type="checkbox" name="grade" value="2"> Sophomore</label>
<label class="checkbox"><input type="checkbox" name="grade" value="3"> Junior</label>
<label class="checkbox"><input type="checkbox" name="grade" value="4"> Senior</label>
<div class="button">
<button class="btn btn-primary" input type="submit" name="submit" href="processor.php">Submit</button>
</div>
</form>
的处理器脚本:
<?php
header("Location: viewpage.html");
$grade = $_POST['grade'];
function Grades() {
if ($grade =="1") {
echo "You're a freshmen";
} elseif ($grade == "2") {
echo "You're a sophomore";
} elseif ($grade == "3") {
echo "You're a junior.";
} elseif ($grade == "4") {
echo "You're a senior.";
} else {
echo "Something is wrong.";
}
}
?>
查看页面:
<h4>Question # 1</h4>
<p><?php Grades();
?>
</p>
本质上讲,我试图让用户填写表格,处理它并吐出输入。例如,他们表示他们是新生,他们点击提交并被带到查看页面,在那里它吐出“你是一名新生。”这是一段时间,因为我编码,这是一个非常简单的问题,我似乎无法找到解决方案。任何帮助将不胜感激。谢谢。
因为,当我到达视图页面时,它什么也没有显示。
问题是...?除了你的处理器基本上通过重定向到另一个页面来中止处理?还有一些可变的范围问题...还有一些不清楚的“这些脚本如何与对方相关”的问题...... – 2013-04-05 15:02:09
我在原帖之后做了一个编辑。我创建了处理器页面,以便可以在后端进行处理,并且可以将PHP和HTML分开。有没有更高效的方法?我遇到的问题是,当它到达视图页面脚本时,函数什么都没有吐出。 – buttonitup 2013-04-05 15:07:09
你能否澄清一下这些脚本如何相互关联?你的意思是我如何将每一个连接到另一个? – buttonitup 2013-04-05 15:08:20