Hello,
I have created a very simple class to create new pages but I'm having problems changing the contents of an array in the new page.
This is the code for the class:
class Page
{
var $content;
var $messages = array ( 'this is value 1' , 'this is value 2' );
function SetContent($newcontent) {
$this->content = $newcontent;
}
function SetMessages($newmessages) {
$this->messages = $newmessages;
}
function DisplayMessages($messages) {
foreach ($messages as $current)
echo $current.'<br> ';
}
function Display() {
echo $this->content;
$this -> DisplayMessages($this->messages);
}
}
and this is the code for the new page:
require ('newpage.php');
$examplepage = new Page();
$examplepage -> SetContent('<p>This is the main content</p>');
$examplepage -> Display();
I would like to be able to change the contents of the $messages array on the new page so that I can enter error messages for a form.
I think I can create the error messages and store them in an array like this:
if (empty($name) ) {
$msg[0] = 'You did not provide your name.<br />';
}
if (empty($surname) ) {
$msg[1] = 'You did not provide your surname.<br />';
}
if (empty($email) ) {
$msg[2] = 'You did not provide your email address.<br />';
}
These error messages will need to replace the contents of the $messages array and show on the new page.
I have tried everything I could think of.
Can anybody help?
Thanks in advance.