Lost again.

Discussion in 'Web Design and Development' started by Cabbit, Apr 29, 2009.

  1. Cabbit macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #1
    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($valueENT_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();
        }
    }
    ?>
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    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.
     
  3. Cabbit thread starter macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #3
    changing it to a public variable made no difference :(
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Have you checked the PHP error log to see if anything shows up there? Are you getting any type of feedback or output?
     
  5. Cabbit thread starter macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #5
    [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.
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    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?
     
  7. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #7
    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!
     
  8. Cabbit thread starter macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
  9. jakeOSX macrumors regular

    Joined:
    Mar 24, 2005
    #9
    throw in semi colons and you'll have most of frustration a programmer finds. :D
     
  10. Cabbit thread starter macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #10
    Problem is that my text reader does not always pick up the mistakes :(
     

Share This Page