Page 1 of 2

Sticky Data

Posted: Tue Dec 21, 2010 11:37 am
by jzmwebdevelopment
I am having an issue with the data from page ID 5 not displaying in the form, Why?

Code: Select all

<?php

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('includes/header.php');

include('includes/class/class.form.php');

include('includes/class/class.page.php');


$iPageID = 5; 

if(isset($_GET["PageID"])){
    
    $iPageID = $_GET["PageID"];
}

$EditedPage = new Page();

$EditedPage->loadPage(5);

$apageInformation = array(); // Information From DB Sticky
$apageInformation["name"] = $EditedPage->getPageName();
$apageInformation["content"] = $EditedPage->getPageContent();

print_r($EditedPage->getPageContent);


$formEdit = new Form('editpage.php?PageID=".$iPageID', 'EditPage','return CheckEditPage();','');

$formEdit->setStickyData($apageInformation);


if(isset($_POST["submit"])){
    
    $formEdit->setStickyData = $_POST;
    
    $formEdit->checkNotEmpty("Name");
    
    $formEdit->checkNotEmpty("PageContent");
    
    if($formEdit->getValid() == true){
        
            $EditedPage->setPageName = $database->escape_value($_POST["Name"]);
                
            $EditedPage->setPageContent = $database->escape_value($_POST["PageContent"]);
                
           $EditedPage->savePage();
        
        $Message = "Page Updated";
        
    }else{
        
        $Message = "You Have An Error Mate";
    }
}


$formEdit->openFieldset();
$formEdit->makeInputBox("Name","Name","CheckInput(this.id);");
$formEdit->makeTextArea("Content", "PageContent", "20","70", "CheckInput(this.id);");
$formEdit->makeSubmitButton("submit","Edit Page");
$formEdit->closeFieldset();

exit;

$newNavigation = new Navigation();


?>

     <?php echo $newNavigation->mainMenu();?>

    <h1  class="Heading">Edit Page</h1>

    <?php echo $Message ?>

   <?php echo $formEdit->getHTML(); ?> 

    <?php include('includes/footer.php')?>

Errors

Notice: Undefined variable: aImage in /home/public_html/Nyken/Admin/includes/class/class.page.php on line 27

Notice: Undefined property: Page::$getPageContent in /home/public_html/Nyken/Admin/editpage.php on line 27

Notice: Undefined index: Name in /home/public_html/Nyken/Admin/includes/class/class.form.php on line 41

Notice: Undefined index: Name in /home/public_html/Nyken/Admin/includes/class/class.form.php on line 42

Notice: Undefined index: PageContent in /home/public_html/Nyken/Admin/includes/class/class.form.php on line 68

Notice: Undefined index: PageContent in /home/public_html/Nyken/Admin/includes/class/class.form.php on line 69

Class - Page

Code: Select all

<?php

require_once('../includes/database.php');

class Page{
    
    private $iID;
    
    private $sPageName;
    
    private $sPageContent;
    
    public function loadPage($iID){
        
        global $database;
        
        $Query = "SELECT * FROM Pages WHERE id =" .$iID;
        
        $resResult = $database->query($Query);
    
        //Fetch The Row
        
        $aPage = $database->fetch_array($resResult);
        
        $this->iID = $aPage["id"];
        $this->sPageName = $aPage["name"];
        $this->sPageContent= $aImage["content"]; // Was get maybe typo
        
        $this->bExisting = true;
    
    }
    
    public function savePage(){
        
        global $database;
        
        if($this->bExisting == false){
            
            $Query = "INSERT INTO Pages(id,name,content) VALUES ('".$this->iID."', '".$this->sPageName."','".$this->sPageContent."')";
            
            $bResult = $database->query($Query);
            
            if($bResult){
                
                $this->iID = $database->get_last_insert_id();
                
                $this->bExisting = true;
                
            }
            else{
                
                die("Save Failed");
            }
            
        }else{
            
            $Query = "UPDATE Pages SET name = '".$this->sPageName."', content = '".$this->sPageContent."' WHERE id =".$this->iID;
            
            echo $Query;
            $bResult = $database->query($Query);
            
        }
    }
        
                // Get Functions
        
    public function getPageID(){
            return $this->iID;
    }    
        
    public function getPageName(){
            return $this->sPageName;
    }
    
    public function getPageContent(){
            return $this->sPageContent;
    }
        
    // Set Functions
    
    public function setImageID($iID){
        
        global $database;
        
        $iID = $database->escape_value($iID);
        
        $this->iID = $iID;
    }    
        
      
    public function setPageName($sPageName){
        
        global $database;
        
        $sPageName = $database->escape_value($sPageName);
        
        $this->sPageName = $sPageName;
    }   
        
    public function setPageContent($sPageContent){
        
        global $database;
        
        $sPageContent = $database->escape_value($sPageContent);
        
        $this->sPageContent = $sPageContent;
    }
    
    
}


//Testing

//Save

//$newImageUpload = new Image();
//$newImageUpload->setImageID(8);
//$newImageUpload->setImageName("Image Class Works");
//$newImageUpload->setImagePath("Image Path Success");
//$newImageUpload->saveImage();



?>

Class-Form

Code: Select all

<?php

require_once('../includes/database.php');


class Form{
    
    private $sHTML;
    private $aStickyData;
    private $aValidationError;
    
    public function __construct($sFormAction, $sID, $JS, $Enctype){
        
        $this->aStickyData = array();
        
        $this->aValidationError = array();
        
        $this->sHTML = "<form id='".$sID."' action='".$sFormAction."' method= 'post' onsubmit='".$JS."' enctype='".$Enctype."'>\n\n";
        
    }
    
    
    public function openFieldset(){
        
	$this->sHTML .= "<fieldset>\n\n"; //attr
    }
    
     public function closeFieldset(){
        
	$this->sHTML .= "</fieldset>\n\n";
    }
        
    public function makeLabel($sLabel, $sName){
        
	$this->sHTML .= "<label for='".$sName."'>".$sLabel.":</label>\n\n";
    }
    
    public function makeInputBox($sLabel,$sName,$JS){
        
        $this->makeLabel($sLabel,$sName);
        $this->sHTML .= "<input type='text' name='".$sName."' id='".$sName."' value='".$this->aStickyData[$sName]."' onblur='".$JS."'/>
                        <div class='Error' id='".$sName."Error'>".$this->aValidationError[$sName]."</div>\n\n";

    }
    

    public function makePasswordBox($sLabel,$sName){
        
        $this->makeLabel($sLabel,$sName);
        $this->sHTML .= "<input type='password' name='".$sName."' id='".$sName."' value='".$this->aStickyData[$sName]."'/>
                        <div class='Error' id='".$sName."Error'>".$this->aValidationError[$sName]."</div>\n\n";
    }
    
    public function makeUpLoadBox($sLabel, $sName){
		
		$this->makeLabel($sLabel, $sName);
		$this->sHTML .= "<input type='file' name='".$sName."' id='".$sName."'/>\n\n";
	}
	
	public function makeHiddenField($sName, $sValue){
		
		$this->sHTML .= "<input type='hidden' name='".$sName."' value='".$sValue."' />\n\n";
	}
	
    public function makeTextArea($sLabel,$sName,$Rows,$Cols, $JS){
        
        $this->makeLabel($sLabel,$sName);
        $this->sHTML .= "<textarea name='".$sName."' id='".$sName."' rows='".$Rows."' cols='".$Cols."' onblur='".$JS."'>". $this->aStickyData[$sName]."</textarea>
	    <div class='Error' id='".$sName."Error'>".$this->aValidationError[$sName]."</div>\n\n";
    }
    
    
    public function makeDropDownList($sLabel, $sName, $aOptions){
        $this->makeLabel($sLabel, $sName);
        $this->sHTML .= "<select name='".$sName."' id='".$sName."'>\n\n";
        
        //To contruct the option list
        foreach($aOptions as $key=>$value){
        
                $this->sHTML .= "<option value='".$key."'>".$value."</option>\n";
        }
                                                
        $this->sHTML .= "</select>
                                        <div id='Error'></div>";
	
    }
    
    public function makeRadioInput($sName, $sLabel, $aRadioOptions){	
		$this->sHtml .= "<label for='" .$sName."'>".$sLabel."</label>\n";
		
		foreach($aRadioOptions as $value => $text){
				
			if ($this->aStickyData[$sName] == $value){
				$this->sHtml .= "<input type='radio' name='".$sName."' value='".$value."' checked class='radio'/><div id='radioText'>".$text."</div>\n";
			}else{
				$this->sHtml .= "<input type='radio' name='".$sName."' value='".$value."' class='radio'/><div id='radioText'>".$text."</div>\n";
			}
		}
			$this->sHtml .= "<div id='Error'>".$this->aValidationError[$sName]."</div>";
	}
    
    public function makeCheckBox($sName, $sValue){
	
		if($this->aStickyData[$sName] == $sValue){
	
			$this->sHTML .= "<input type='checkbox' name='".$sName."' id='".$sName."' value='".$sValue."' checked='checked' /><p id='agreeTerm'>".$sValue."</p>\n";
		}	
		else{
		$this->sHTML .= "<input type='checkbox' name='".$sName."' id='".$sName."' value='".$sValue."' /><p id='agreeTerm'>".$sValue."</p>\n";
		}
    }
    
    	public function checkUpload($sName, $sMimeType, $iSize){
		
		$Message = "";
	
		if(empty($_FILES[$sName]["name"])){
			
			$Message = "No files specified";
			
		}elseif($_FILES[$sName]['error'] != UPLOAD_ERR_OK){
				
			$Message = "File cannot be uploaded";
				
		}elseif($_FILES[$sName]["type"] != $sMimeType){
					
			$Message = "Only ".  $sMimeType ." format can be uploaded";
					
		}elseif($_FILES["sName"]["size"] > $iSize){
			
			$Message = "Files cannot exceed ".$iSize." bytes in size";
			
		}
		
		//if there is any error, Assign error message to aValidationError 
		if ($Message != ""){
			$this->aValidationError[$sName] = $Message;
		}
	}
		
	
	public function Upload($sName, $sNewFileName){
		
		$newname = dirname(__FILE__).'../images/Gallery/'.$sNewFileName;
		
		move_uploaded_file($_FILES[$sName]['tmp_name'],$newname);
    	}
    
    public function checkNotEmpty($sName){
	
	if(strlen($this->aStickyData[$sName]) == 0)
	
	$this->aValidationError[$sName] = "* Required";
    }
    
        
    public function makeLinkButton($sName, $Value){
	
	$this->sHTML .= "<a href='".$sName.".php'>"."<input name='".$sName."' id = '".$sName."' type='button' value=".$Value." />"."</a>";
	
    }  
    

    public function makeSubmitButton($sName, $Value){
	
	$this->sHTML .= "<input name='".$sName."' id = '".$sName."' type='submit' value='".$Value."' />\n\n";
	
    }
    
    public function makeResetButton($sName, $Value){
	
	$this->sHTML .= "<input name='".$sName."' id = '".$sName."' type='reset' value='".$Value."' />";
	
    } 

    public function getHTML(){
        
        $this->sHTML .="</form>";
        return $this->sHTML;
    }
    
    public function getValid(){
	
	if (count($this->aValidationError) == 0){
	    
	    return true;
	
	}else{
	    
	    return false;
	}
    }
    
    
    public function setStickyData($aData){
        
        $this->aStickyData = $aData;
    }
    
    
    
}



?>

Re: Sticky Data

Posted: Tue Dec 21, 2010 12:26 pm
by Darhazer
Fix the listet erros first

Code: Select all

print_r($EditedPage->getPageContent);
should be

Code: Select all

print_r($EditedPage->getPageContent());
$aPageContent has 'name' and 'content' while you try to use 'Name' and 'PageContent'. So verify the names, both in PHP and HTML

Re: Sticky Data

Posted: Tue Dec 21, 2010 12:49 pm
by jzmwebdevelopment
Thanks for your quick reply.

I have fixed above but still get:

Notice: Undefined variable: aImage in /home/devnoo/public_html/Nyken/Admin/includes/class/class.page.php on line 27

Notice: Undefined index: Name in /home/devnoo/public_html/Nyken/Admin/includes/class/class.form.php on line 42

Notice: Undefined index: PageContent in /home/devnoo/public_html/Nyken/Admin/includes/class/class.form.php on line 69

I have looked over the code and I am drawing blanks.

Re: Sticky Data

Posted: Tue Dec 21, 2010 12:51 pm
by Darhazer
The fist one is obvious:

Code: Select all

$this->sPageName = $aPage["name"];
        $this->sPageContent= $aImage["content"]; // Was get maybe typo
Most likely it should be:

Code: Select all

$this->sPageName = $aPage["name"];
        $this->sPageContent= $aPage["content"]; // Was get maybe typo
As for the rest, can you please post the edited code (only the fist one, not the Page and Form classes)

Re: Sticky Data

Posted: Tue Dec 21, 2010 1:07 pm
by jzmwebdevelopment
Thanks,

I am now getting somewhere:

I now have the content being showen like on the "client side view" and the following errors:

Notice: Undefined index: Name in /home/devnoo/public_html/Nyken/Admin/includes/class/class.form.php on line 42

Notice: Undefined index: PageContent in /home/devnoo/public_html/Nyken/Admin/includes/class/class.form.php on line 69

Code: Select all

<?php

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('includes/header.php');

include('includes/class/class.form.php');

include('includes/class/class.page.php');


$iPageID = 5; 

if(isset($_GET["PageID"])){
    
    $iPageID = $_GET["PageID"];
}

$EditedPage = new Page();

$EditedPage->loadPage(5);

$apageInformation = array(); // Information From DB Sticky
$apageInformation["Name"] = $EditedPage->getPageName();
$apageInformation["PageContent"] = $EditedPage->getPageContent();

print_r($EditedPage->getPageContent());


$formEdit = new Form('editpage.php?PageID=".$iPageID', 'EditPage','return CheckEditPage();','');

$formEdit->setStickyData($apageInformation);


if(isset($_POST["submit"])){
    
    $formEdit->setStickyData = $_POST;
    
    $formEdit->checkNotEmpty("Name");
    
    $formEdit->checkNotEmpty("PageContent");
    
    if($formEdit->getValid() == true){
        
            $EditedPage->setPageName = $database->escape_value($_POST["Name"]);
                
            $EditedPage->setPageContent = $database->escape_value($_POST["PageContent"]);
                
           $EditedPage->savePage();
        
        $Message = "Page Updated";
        
    }else{
        
        $Message = "You Have An Error Mate";
    }
}


$formEdit->openFieldset();
$formEdit->makeInputBox("Name","Name","CheckInput(this.id);");
$formEdit->makeTextArea("Content", "PageContent", "20","70", "CheckInput(this.id);");
$formEdit->makeSubmitButton("submit","Edit Page");
$formEdit->closeFieldset();

exit;

$newNavigation = new Navigation();


?>

     <?php echo $newNavigation->mainMenu();?>

    <h1  class="Heading">Edit Page</h1>

    <?php echo $Message ?>

   <?php echo $formEdit->getHTML(); ?> 

    <?php include('includes/footer.php')?>

Re: Sticky Data

Posted: Tue Dec 21, 2010 2:20 pm
by Darhazer
I think the problem is in:

Code: Select all

$this->sHTML .= "<input type='text' name='".$sName."' id='".$sName."' value='".$this->aStickyData[$sName]."' onblur='".$JS."'/>
                        <div class='Error' id='".$sName."Error'>".$this->aValidationError[$sName]."</div>\n\n";
This should be:

Code: Select all

$this->sHTML .= "<input type='text' name='".$sName."' id='".$sName."' value='".$this->aStickyData[$sName]."' onblur='".$JS."'/>";
if (isset($this->aValidationError[$sName])){
    $this->sHTML .= "<div class='Error' id='".$sName."Error'>".$this->aValidationError[$sName]."</div>\n\n";
}
This is applicable to makeInputBox(), makePasswordBox(), makeUpLoadBox(), makeTextArea(), makeRadioInput() and makeCheckBox() methods

Re: Sticky Data

Posted: Tue Dec 21, 2010 2:41 pm
by jzmwebdevelopment
Thanks,

I am not sure how I would modify my makeRadioInput() and makeCheckBox() methods.

The errors that I had have now gone but it is not editable text - it should show within the form.

Jess

Re: Sticky Data

Posted: Thu Dec 23, 2010 11:29 am
by ccsdg
Re makeCheckBox() and makeRadioButton():
That depends how they are currently structured. If you're not validating your checkboxes and radio buttons (I assume you're not) then they'll never generate anything in aValidationError. And you won't need an error message div for displaying them, so you can just leave what is now that isset block out entirely.

'not editable text - it should show within the form.':
What text are you referring to here? What HTML is currently being generated?

Re: Sticky Data

Posted: Thu Dec 23, 2010 12:00 pm
by jzmwebdevelopment
I am getting the following:

http://cl.ly/3H2O3z0t3c2d3K2X1h1k

and the HTML is



<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nyken Builders LTD - Pride In What We Do</title>
<script src="includes/js/validation.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="includes/css/style.css" />
</head>
<body>

<div id="Container">

<div id="Content">

<div class="Header">

<h1><img src="includes/images/nyken.jpg" width="170" height="145" alt="Nyken Builders LTD - Pride in what we do"/></h1>

</div><!--Header End -->


Whether your in the market for a major renovation or minor alteration Nyken builders have the experience and knowledge to look after all your requirements.

The benefits of being and using a Certified Builder means you will have the confidence in us, and assurance that the job will be done right the first time, and done well . A comprehensive range of building contracts are available, Full Contract , Cost Reimbursement, or Labour Only. We can ever offer 'Homefirst 10 year builders guarantee'

We have been in the industry for 20 years and in this time have established a great relationship with both building merchants and subtrades. which we can rely on to see your project is done cost effectively and with subtrades i can depend on.

Re: Sticky Data

Posted: Thu Dec 23, 2010 12:09 pm
by ccsdg
Thanks jzm. I don't see a form anywhere. Did you echo out the form? And is that whole block of text supposed to be editable inside the form, as a textarea or something?

Re: Sticky Data

Posted: Thu Dec 23, 2010 12:18 pm
by jzmwebdevelopment
ccsdg wrote:Thanks jzm. I don't see a form anywhere. Did you echo out the form? And is that whole block of text supposed to be editable inside the form, as a textarea or something?
This is my PHP for the page and the page title should be editable in Name and content editable in Pagecontent:

Code: Select all


<?php

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('includes/header.php');

include('includes/class/class.form.php');

include('includes/class/class.page.php');


$iPageID = 5; 

if(isset($_GET["PageID"])){
    
    $iPageID = $_GET["PageID"];
}

$EditedPage = new Page();

$EditedPage->loadPage(5);

$apageInformation = array(); // Information From DB Sticky
$apageInformation["Name"] = $EditedPage->getPageName();
$apageInformation["PageContent"] = $EditedPage->getPageContent();

print_r($EditedPage->getPageContent());


$formEdit = new Form('editpage.php?PageID=".$iPageID', 'EditPage','return CheckEditPage();','');

$formEdit->setStickyData($apageInformation);


if(isset($_POST["submit"])){
    
    $formEdit->setStickyData = $_POST;
    
    $formEdit->checkNotEmpty("Name");
    
    $formEdit->checkNotEmpty("PageContent");
    
    if($formEdit->getValid() == true){
        
            $EditedPage->setPageName = $database->escape_value($_POST["Name"]);
                
            $EditedPage->setPageContent = $database->escape_value($_POST["PageContent"]);
                
           $EditedPage->savePage();
        
        $Message = "Page Updated";
        
    }else{
        
        $Message = "You Have An Error Mate";
    }
}


$formEdit->openFieldset();
$formEdit->makeInputBox("Name","Name","CheckInput(this.id);");
$formEdit->makeTextArea("Content", "PageContent", "20","70", "CheckInput(this.id);");
$formEdit->makeSubmitButton("submit","Edit Page");
$formEdit->closeFieldset();

exit;

$newNavigation = new Navigation();


?>

     <?php echo $newNavigation->mainMenu();?>

    <h1  class="Heading">Edit Page</h1>

    <?php echo $Message ?>

   <?php echo $formEdit->getHTML(); ?> 

    <?php include('includes/footer.php')?>


Re: Sticky Data

Posted: Thu Dec 23, 2010 12:41 pm
by ccsdg
I assume this is what's supposed to appear in the textarea:
Whether your in the market for a major renovation or minor alteration Nyken builders have the experience and knowledge to look after all your requirements.

The benefits of being and using a Certified Builder means you will have the confidence in us, and assurance that the job will be done right the first time, and done well . A comprehensive range of building contracts are available, Full Contract , Cost Reimbursement, or Labour Only. We can ever offer 'Homefirst 10 year builders guarantee'

We have been in the industry for 20 years and in this time have established a great relationship with both building merchants and subtrades. which we can rely on to see your project is done cost effectively and with subtrades i can depend on.
Not sure where the name is appearing - is that appearing at all?

To sum up what you are seeing, you're echoing out the form after constructing it, and it appears to have constructed no form and just given you the content - and possibly no name either. (I'm going to assume that's right, but correct me if it's not.) Since you seem to be passing stuff to it correctly, the problem then goes back to a form method. Common mistakes could be:
- constructing tags and not adding them to the storing property (eg $sHTML). fix: add them
- not constructing tags - maybe you deleted them by mistake - and just echoing out the content. fix: echo out html inside the method to see what's not being constructed, then put them in.
- using '=' when you meant '.='. This is effectively overriding every previous assignment. (NB: This one is likely if you have no page name coming out as well, though here you'd at least expect a closing textarea tag, unless that got deleted too.)
- constructing everything correctly, and then in your get method not referring to the correct property. If your getHTML method is anything like mine, you'll add a closing form tag just before you return it. See if you have a closing form tag echoing out. (EDIT: I don't think this is your problem because it was working before.)

and maybe it's none of the above :p. Do some echo's and print_r's, working backwards from the getHTML(), and see if what you're expecting at each stage matches up with what you're seeing.

HTH

Re: Sticky Data

Posted: Thu Dec 23, 2010 1:00 pm
by jzmwebdevelopment
I had

print_r($EditedPage->getPageContent()); = page content

And now I cant get my form to show :(

Any ideas

Re: Sticky Data

Posted: Thu Dec 23, 2010 1:08 pm
by ccsdg
Did you go back into your form class and trace back from the getHTML()? (what variables it's taking from, print_r-ing them). Once you figure out which method is going wrong, you should be able to fix it and get your form echoing out.

You can do the same with your page class too

Re: Sticky Data

Posted: Thu Dec 23, 2010 1:18 pm
by jzmwebdevelopment
But the thing is the form class is working on other pages