Hi lads,
New here.
Just wondering if anyone can help me. Im getting :
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster. Error 403 "
My PHP code is :
<?php
if (isset($_REQUEST['button']))
{
$error = validate_form();
if ($error)
{
display_form_page ($error);
}
else
{
display_output_page();
}
}
else
{
display_form_page('');
}
?>
<?php
function display_form_page($error)
{
$self = $_SERVER['PHP_SELF'];
$first_name = isset($_REQEST['firstname']) ? $_REQUEST['firstname'] : '';
$last_name = isset($_REQEST['lastname']) ? $_REQUEST['lastname'] : '';
$wines = isset($_REQEST['wines']) ? $_REQUEST['wines'] : '';
?>
<html>
<head>
<link rel="stylesheet">
<title>Sticky Checkboxes</title>
<style type="text/css">
.error{ color:#ff0000;}
</style>
</head>
<body>
<h1>Sticky Checkboxes</h1>
<?php
if($error)
{
echo "<p>$error</p>\n";
}
?>
<form action="<?phpecho $self ?>" method="GET">
<p>First name: <input class ="input" type="text" name="firstname"
value ="<?php echo $first_name?>"</p>
<p>Last name: <input class="input" type="text" name="lastname"
value ="<?php echo $last_name?>"</p>
<p>Chose your favourite wines:</p>
Shiraz <input type ="checkbox" name="wines[]"value="shiraz" <?php
check($wines,"shiraz")?>>
Merlot <input type ="checkbox" name="wines[]"value="merlot" <?php
check($wines,"merlot")?>>
Chianti <input type ="checkbox" name="wines[]"value="chianti" <?php
check($wines,"chianti")?>>
<p><input type="submit" name="button" value="Submit Name"></p>
</form>
</body>
</html>
<?php
}
?> //end of DISPLAY_FORM PAGE
<?php
function check($wines, $val)
{
if (is_array($wines) and in_aray($val,$wines))
{
echo 'checked = "checked"';
}
}
?>
<?php
function validate_form()
{
$first_name = trim($_REQUEST['firstname']);
$last_name = trim($_REQUEST['lastname']);
$wines = isset($_REQUEST['firstname']) ? $_REQUEST['wines'] : '';
$error='';
$reg_exp = "/^[a-zA-Z'-]+$/";
if (! preg_match($reg_exp, $first_name))
{
$error .=
"<span class=\"error\">First name is invalid (letters, hyphens, ', only)</span><br>";
}
if (! preg_match($reg_exp, $last_name))
{
$error .=
"<span class=\"error\">Last name is invalid (letters, hyphens, ', only)</span><br>";
}
if (! is_array($wines))
{
$error.= "<span class=\"error\">You must select at least one wine</span></br>";
}
return $error; }
function display_output_page()
{
$first_name = trim($_REQUEST['firstname']);
$last_name = trim($_REQUEST['lastname']);
$wines = isset($_REQUEST['wines']) ? $_REQUEST['wines'] : '' ;
?>
<html>
<head><title>Form Results</title></head>
<body>
<h1>Form Results</h1> </body>
</html>
<?php
echo "Hello $first_name $last_name</br>\n";
if (is_array($wines))
{
echo "Favourite wines are ";
foreach ($wines as $wine)
{
echo $wine. " ";
}
}}
?>
All help greatly appreciated.
Thanks ,
Dave