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>
(process.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コードを追加する必要がありますか?
このコードをリンクに追加するにはどうすればよいですか。
エラーがエコーバックされるのを防ぐために、次の記事と前の記事のリンクが特定のチャプターに存在しない配列にアクセスしなくなったため、最後の記事または最初の記事がエコーされたときにページに何をすべきか。
ありがとうございました!