我想知道如何在使用它从 process.php 上的 $laws 数组中检索特定文章之前验证来自 form.php 的数据
(form.php)
<form action="process.php" method="get">
Group:
<select name="group">
<option value="group1">Group1</option>
<option value="group2">Group2</option>
</select>
Chapter:
<input type="text" name="chapter">
Article:
<input type="text" name="article">
<input type="submit" value="Go to Article">
</form>
(进程.php)
<?php
session_start();
$laws=array(
"group1"=>array(
"1"=>array(
"1"=>"This is article (1) in chapter (1) of (group1)",
"2"=>"This is article (2) in chapter (1) of (group1)",
"3"=>"This is article (3) in chapter (1) of (group1)",
),
"2"=>array(
"1"=>"This is article (1) in chapter (2) of (group1)",
"2"=>"This is article (2) in chapter (2) of (group1)",
"3"=>"This is article (3) in chapter (2) of (group1)",
),
),
"group2"=>array(
"1"=>array(
"1"=>"This is article (1) in chapter (1) of (group2)",
"2"=>"This is article (2) in chapter (1) of (group2)",
"3"=>"This is article (3) in chapter (1) of (group2)",
),
"2"=>array(
"1"=>"This is article (1) in chapter (2) of (group2)",
"2"=>"This is article (2) in chapter (2) of (group2)",
"3"=>"This is article (3) in chapter (2) of (group2)",
),
)
);
$_SESSION['group'] = $_GET['group'];
$_SESSION['chapter'] = $_GET['chapter'];
$_SESSION['article'] = $_GET['article'];
$group = $_SESSION['group'];
$chapter = $_SESSION['chapter'];
$article = $_SESSION['article'];
// Echo Article from Laws Array
echo $group . " chapter" . $chapter . " article" . $article . "<br/>";
echo $laws[$group][$chapter][$article];
?>
<br/>
<a href="sample.php">PREVIOUS Articles</a> <a href="sample.php">NEXT Articles</a>
问题 1
在使用来自 $_GET 变量的数据设置 $_SESSION 值之前,如何使用以下方案验证表单中的 $_GET 值?
Data in CHAPTER and ARTICLE input forms:
are not empty;
are numbers;
are not less than or greater than the existing array Chapters and Article numbers;
do not have spaces;
do not have decimals;
do not have letters;
do not have negative, positive and; or other signs;
问题2
我应该在下一篇文章和上一篇文章链接中添加什么 PHP 代码,以在当前回显的文章之后回显下一篇文章?
我应该如何将此代码添加到链接中;
由于 NEXT Article 和 PREVIOUS Article 链接将不再访问特定章节中不存在的数组,以防止 ERRORS 被回显,因此当最后一篇文章或第一篇文章被回显时,应该对页面执行什么操作。
谢谢!