Validating FORM data to use for retrieving values from Multidimensional Array in PHP
<p>I would like to know how I can validate data from the form.php before using it to retreive a specific article from the $laws array on process.php</p>

<p>(form.php)</p>

<pre><code>&lt;form action="process.php" method="get"&gt;
Group:
&lt;select name="group"&gt;
    &lt;option value="group1"&gt;Group1&lt;/option&gt;
    &lt;option value="group2"&gt;Group2&lt;/option&gt;
&lt;/select&gt;

Chapter:
&lt;input type="text" name="chapter"&gt;

Article:
&lt;input type="text" name="article"&gt;

&lt;input type="submit" value="Go to Article"&gt;

&lt;/form&gt;
</code></pre>

<p>(process.php)</p>

<pre><code>&lt;?php
session_start();
$laws=array(
       "group1"=&gt;array(
                      "1"=&gt;array(
                                "1"=&gt;"This is article (1) in chapter (1) of (group1)",
                                "2"=&gt;"This is article (2) in chapter (1) of (group1)",
                                "3"=&gt;"This is article (3) in chapter (1) of (group1)",
                                ),
                      "2"=&gt;array(
                                "1"=&gt;"This is article (1) in chapter (2) of (group1)",
                                "2"=&gt;"This is article (2) in chapter (2) of (group1)",
                                "3"=&gt;"This is article (3) in chapter (2) of (group1)",
                                ),
                       ),
       "group2"=&gt;array(
                      "1"=&gt;array(
                                "1"=&gt;"This is article (1) in chapter (1) of (group2)",
                                "2"=&gt;"This is article (2) in chapter (1) of (group2)",
                                "3"=&gt;"This is article (3) in chapter (1) of (group2)",
                                ),
                      "2"=&gt;array(
                                "1"=&gt;"This is article (1) in chapter (2) of (group2)",
                                "2"=&gt;"This is article (2) in chapter (2) of (group2)",
                                "3"=&gt;"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 . "&lt;br/&gt;";
echo $laws[$group][$chapter][$article];

?&gt;

&lt;br/&gt;

&lt;a href="sample.php"&gt;PREVIOUS Articles&lt;/a&gt; &lt;a href="sample.php"&gt;NEXT Articles&lt;/a&gt;
</code></pre>

<p>Question 1</p>

<p>Before setting $_SESSION values with data from $_GET variables, how do I validate the $_GET values from the form with the following scheme?</p>

<pre><code>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;
</code></pre>

<p>Question 2</p>

<p>What PHP code should I add to the NEXT Article and PREVIOUS Article links, to echo the next article after the currently echoed article? </p>

<p>how should I add this code to the links;</p>

<p>what should be done to the page when the the last article or the first article has been echoed since the NEXT Article and PREVIOUS Article links wouldn't access anymore non-existent arrays in a particular chapter to prevent ERRORS being echoed back.</p>

<p>Thank you!</p>
