Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Cabbit

macrumors 68020
Original poster
Jan 30, 2006
2,128
1
Scotland
Hey folks i been working on a bbcode thingie in javascript and i am trying to send the post to a new class for sanitizing and converting the bb tags but i can't seem to get the class to return anything.

this is demo.php well a snippet of it, i have checked that $_POST['post'] does have a value so no issues there.
PHP:
echo '<a href="demo.php">Back</a><br />';
	
	require_once('textarea.class.php');
		
	// Set up a new class
	$test = new validate_textarea();
		
	// Send post to validate class
	$test->post = $_POST['post'];
	
	// Return any errors
	$test->error_return();
	
	// Return the valid output bbcode
	$test->return_bbcode();
	
	// Return the valid output html
	$test->return_formatedhtml();

and this is the new class in development hopefully how php5 likes it.
PHP:
<?php
/************************************************************************************
  								Kittenbunny CMS
 								Filename: textarea.class.php
 								Class: Validate Textarea 
************************************************************************************/

class validate_textarea
{
	// Variables
  	private $post;
	
	// Function to remove html tags //
	private function sanitize_htmltags()
	{
		$value = $this->post;
		
		// Removing the leading space that is annoying. //
		$value = preg_replace('/ /i', '', $value);

		// Sets the allowed taggs //
		$value = preg_replace('/<\/?(?:\b(?!)[^>]+?)>/i', '', $value);  
	
		// Does the htmlspecialchars bit //
		$value = htmlspecialchars($value, ENT_QUOTES, "UTF-8"); 
		
		return $value;
	}
	
	// Function to convert the bbtages to html. //
	private function bbtags()
	{
	
	}
	
	// Function to return errors. //
	public function error_return()
	{
		return $this->sanitize_htmltags();
	}
	
	// Function to return the post with bbcode. html tags removed. //
	public function return_bbcode()
	{
		return $this->sanitize_htmltags();
	}
	
	// Function to return the post in html format for display. //
	public function return_formatedhtml()
	{
		return $this->sanitize_htmltags();
	}
}
?>
 
I might be wrong on this as I haven't done much OOPHP, but for this line,
PHP:
$test->post = $_POST['post'];
You're accessing $post, which is a private variable in the class. I don't believe you can access it directly. I think you may need a public setPost function to call that assign the $_POST value.
 
Have you checked the PHP error log to see if anything shows up there? Are you getting any type of feedback or output?
 
Have you checked the PHP error log to see if anything shows up there? Are you getting any type of feedback or output?

[29-Apr-2009 21:15:26] PHP Fatal error: Call to undefined method validate_textarea::set_post() in /Users/davidroy/AB Comforts/Website/HTML/development_directory/include/class/demo.php on line 62
[29-Apr-2009 21:15:45] PHP Fatal error: Call to undefined method validate_textarea::set_post() in /Users/davidroy/AB Comforts/Website/HTML/development_directory/include/class/demo.php on line 62


EDIT: i miss spelled require_once i think and used return instead of echo.
 
[29-Apr-2009 21:15:26] PHP Fatal error: Call to undefined method validate_textarea::set_post() in /Users/davidroy/AB Comforts/Website/HTML/development_directory/include/class/demo.php on line 62
[29-Apr-2009 21:15:45] PHP Fatal error: Call to undefined method validate_textarea::set_post() in /Users/davidroy/AB Comforts/Website/HTML/development_directory/include/class/demo.php on line 62

So it looks like you added to the code you posted before to include a method named set_post. Is that method public? And, just to check, is the updated textarea.class.php file uploaded into the right spot?
 
I tried out the code you put up. It runs for me when I changed the $post variable from private to public. Here's the code I tested with. I had to make some modifications since I don't have your setup.
PHP:
<?php
require_once('textarea.class.php');
        
// Set up a new class
$test = new validate_textarea();
    
// Send post to validate class
//$test->post = $_POST['post'];
$test->post = 'hi!';

// Return any errors
echo "<p>error: ". $test->error_return() .'</p>';

// Return the valid output bbcode
echo "<p>bbcode: ". $test->return_bbcode() .'</p>';

// Return the valid output html
echo "<p>format: ". $test->return_formatedhtml() .'</p>';
?>
Which gave me an output of,
Code:
error: hi!

bbcode: hi!

format: hi!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.