Validating form data for a multidimensional array

Hello,
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

(form.php)
[php]

Group: Group1 Group2

Chapter:

Article:

[/php]

(process.php)
[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 . "
"; echo $laws[$group][$chapter][$article]; ?>

PREVIOUS Articles NEXT Articles
[/php]

Question 1

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

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;

Question 2

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

how should I add this code to the links;

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.

Thank you!

Sponsor our Newsletter | Privacy Policy | Terms of Service