Skip to main content
Tweeted twitter.com/#!/StackCodeReview/status/265404900119298048
improves formatting
Source Link
palacsint
  • 30.4k
  • 9
  • 82
  • 157

I am new at OOP and iI wonder if the code below is OOP or it can be better and also what can be better? Kr Bas

class cForm{

class cForm{
   
    private $_TagAction;
    private $_TagMethod;
    private $_TagName;
    private $_TagExtraAttr;
    
    //var form field
    private $_FieldType;
    private $_FieldName;
    
    //var button
    private $_ButtonValue;
    private $_ButtonName;

    public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
        $this->_TagAction = $_TagAction;
        $this->_TagMethod = $_TagMethod;
        $this->_TagName = $_TagName;
        $this->_TagExtraAttr = $_TagExtraAttr;
        
    }

    public function getTagOpen(){
        return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
    }
    
    public function setFormField( $FieldType , $FieldName ){
        $this->_FieldType = $FieldType;
        $this->_FieldName = $FieldName;
    }    
    
    public function getFormField(){
        return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
    }


    public function setButton( $ButtonValue , $ButtonName ){
        $this->_ButtonValue = $ButtonValue;
        $this->_ButtonName = $ButtonName;
    }

    public function getButton(){
        return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
    }

    public function getTagEnd(){
        return '</form>' . PHP_EOL;
    }

}

    
}



$objForm = new cForm( '/' , 'post'  , 'test' , 'onsubmit="test"' );
echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2');
echo $objForm->getFormField();

echo $objForm->setButton('test value','test name');
echo $objForm->getButton();

echo $objForm->getTagEnd();

I am new at OOP and i wonder if the code below is OOP or it can be better and also what can be better? Kr Bas

class cForm{

private $_TagAction;
private $_TagMethod;
private $_TagName;
private $_TagExtraAttr;

//var form field
private $_FieldType;
private $_FieldName;

//var button
private $_ButtonValue;
private $_ButtonName;

public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
    $this->_TagAction = $_TagAction;
    $this->_TagMethod = $_TagMethod;
    $this->_TagName = $_TagName;
    $this->_TagExtraAttr = $_TagExtraAttr;
    
}

public function getTagOpen(){
    return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
}

public function setFormField( $FieldType , $FieldName ){
    $this->_FieldType = $FieldType;
    $this->_FieldName = $FieldName;
}    

public function getFormField(){
    return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
}


public function setButton( $ButtonValue , $ButtonName ){
    $this->_ButtonValue = $ButtonValue;
    $this->_ButtonName = $ButtonName;
}

public function getButton(){
    return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
}

public function getTagEnd(){
    return '</form>' . PHP_EOL;
}

}

$objForm = new cForm( '/' , 'post'  , 'test' , 'onsubmit="test"' );
echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2');
echo $objForm->getFormField();

echo $objForm->setButton('test value','test name');
echo $objForm->getButton();

echo $objForm->getTagEnd();

I am new at OOP and I wonder if the code below is OOP or it can be better and also what can be better?

class cForm{
   
    private $_TagAction;
    private $_TagMethod;
    private $_TagName;
    private $_TagExtraAttr;
    
    //var form field
    private $_FieldType;
    private $_FieldName;
    
    //var button
    private $_ButtonValue;
    private $_ButtonName;

    public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
        $this->_TagAction = $_TagAction;
        $this->_TagMethod = $_TagMethod;
        $this->_TagName = $_TagName;
        $this->_TagExtraAttr = $_TagExtraAttr;
        
    }

    public function getTagOpen(){
        return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
    }
    
    public function setFormField( $FieldType , $FieldName ){
        $this->_FieldType = $FieldType;
        $this->_FieldName = $FieldName;
    }    
    
    public function getFormField(){
        return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
    }


    public function setButton( $ButtonValue , $ButtonName ){
        $this->_ButtonValue = $ButtonValue;
        $this->_ButtonName = $ButtonName;
    }

    public function getButton(){
        return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
    }

    public function getTagEnd(){
        return '</form>' . PHP_EOL;
    }
    
}



$objForm = new cForm( '/' , 'post'  , 'test' , 'onsubmit="test"' );
echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2');
echo $objForm->getFormField();

echo $objForm->setButton('test value','test name');
echo $objForm->getButton();

echo $objForm->getTagEnd();
added 16 characters in body
Source Link

I am new at OOP and i wonder if the code below is OOP or it can be better and also what can be better? Kr Bas

class cForm{

private $_TagAction;
private $_TagMethod;
private $_TagName;
private $_TagExtraAttr;

//var form field
private $_FieldType;
private $_FieldName;

//var button
private $_ButtonValue;
private $_ButtonName;

public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
    $this->_TagAction = $_TagAction;
    $this->_TagMethod = $_TagMethod;
    $this->_TagName = $_TagName;
    $this->_TagExtraAttr = $_TagExtraAttr;
    
}

public function getTagOpen(){
    return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
}

public function setFormField( $FieldType , $FieldName ){
    $this->_FieldType = $FieldType;
    $this->_FieldName = $FieldName;
}    

public function getFormField(){
    return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
}


public function setButton( $ButtonValue , $ButtonName ){
    $this->_ButtonValue = $ButtonValue;
    $this->_ButtonName = $ButtonName;
}

public function getButton(){
    return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
}

public function getTagEnd(){
    return '</form>' . PHP_EOL;
}

}

$objForm = new cForm( '/' , 'post'  , 'test' , 'onsubmit="test"' );
echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2');
echo $objForm->getFormField();

echo $objForm->setButton('test value','test name');
echo $objForm->getButton();

echo $objForm->getTagEnd();

I am new at OOP and i wonder if the code below is OOP or it can be better and also what can be better? Kr Bas

private $_TagAction;
private $_TagMethod;
private $_TagName;
private $_TagExtraAttr;

//var form field
private $_FieldType;
private $_FieldName;

//var button
private $_ButtonValue;
private $_ButtonName;

public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
    $this->_TagAction = $_TagAction;
    $this->_TagMethod = $_TagMethod;
    $this->_TagName = $_TagName;
    $this->_TagExtraAttr = $_TagExtraAttr;
    
}

public function getTagOpen(){
    return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
}

public function setFormField( $FieldType , $FieldName ){
    $this->_FieldType = $FieldType;
    $this->_FieldName = $FieldName;
}    

public function getFormField(){
    return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
}


public function setButton( $ButtonValue , $ButtonName ){
    $this->_ButtonValue = $ButtonValue;
    $this->_ButtonName = $ButtonName;
}

public function getButton(){
    return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
}

public function getTagEnd(){
    return '</form>' . PHP_EOL;
}

}

$objForm = new cForm( '/' , 'post'  , 'test' , 'onsubmit="test"' );
echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2');
echo $objForm->getFormField();

echo $objForm->setButton('test value','test name');
echo $objForm->getButton();

echo $objForm->getTagEnd();

I am new at OOP and i wonder if the code below is OOP or it can be better and also what can be better? Kr Bas

class cForm{

private $_TagAction;
private $_TagMethod;
private $_TagName;
private $_TagExtraAttr;

//var form field
private $_FieldType;
private $_FieldName;

//var button
private $_ButtonValue;
private $_ButtonName;

public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
    $this->_TagAction = $_TagAction;
    $this->_TagMethod = $_TagMethod;
    $this->_TagName = $_TagName;
    $this->_TagExtraAttr = $_TagExtraAttr;
    
}

public function getTagOpen(){
    return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
}

public function setFormField( $FieldType , $FieldName ){
    $this->_FieldType = $FieldType;
    $this->_FieldName = $FieldName;
}    

public function getFormField(){
    return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
}


public function setButton( $ButtonValue , $ButtonName ){
    $this->_ButtonValue = $ButtonValue;
    $this->_ButtonName = $ButtonName;
}

public function getButton(){
    return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
}

public function getTagEnd(){
    return '</form>' . PHP_EOL;
}

}

$objForm = new cForm( '/' , 'post'  , 'test' , 'onsubmit="test"' );
echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2');
echo $objForm->getFormField();

echo $objForm->setButton('test value','test name');
echo $objForm->getButton();

echo $objForm->getTagEnd();

I am new at OOP and i wonder if the code below is OOP or it can be better and also what can be better? Kr Bas

private $_TagAction;
private $_TagMethod;
private $_TagName;
private $_TagExtraAttr;

//var form field
private $_FieldType;
private $_FieldName;

//var button
private $_ButtonValue;
private $_ButtonName;

public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
    $this->_TagAction = $_TagAction;
    $this->_TagMethod = $_TagMethod;
    $this->_TagName = $_TagName;
    $this->_TagExtraAttr = $_TagExtraAttr;
    
}

public function getTagOpen(){
    return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
}

public function setFormField( $FieldType , $FieldName ){
    $this->_FieldType = $FieldType;
    $this->_FieldName = $FieldName;
}    

public function getFormField(){
    return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
}


public function setButton( $ButtonValue , $ButtonName ){
    $this->_ButtonValue = $ButtonValue;
    $this->_ButtonName = $ButtonName;
}

public function getButton(){
    return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
}

public function getTagEnd(){
    return '</form>' . PHP_EOL;
}

}

$objForm = new cForm( '/' , 'post' , 'test' , 'onsubmit="test"' ); echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2'); echo $objForm->getFormField();

echo $objForm->setButton('test value','test name'); echo $objForm->getButton();

echo $objForm->getTagEnd();

$objForm = new cForm( '/' , 'post'  , 'test' , 'onsubmit="test"' );
echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2');
echo $objForm->getFormField();

echo $objForm->setButton('test value','test name');
echo $objForm->getButton();

echo $objForm->getTagEnd();

I am new at OOP and i wonder if the code below is OOP or it can be better and also what can be better? Kr Bas

private $_TagAction;
private $_TagMethod;
private $_TagName;
private $_TagExtraAttr;

//var form field
private $_FieldType;
private $_FieldName;

//var button
private $_ButtonValue;
private $_ButtonName;

public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
    $this->_TagAction = $_TagAction;
    $this->_TagMethod = $_TagMethod;
    $this->_TagName = $_TagName;
    $this->_TagExtraAttr = $_TagExtraAttr;
    
}

public function getTagOpen(){
    return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
}

public function setFormField( $FieldType , $FieldName ){
    $this->_FieldType = $FieldType;
    $this->_FieldName = $FieldName;
}    

public function getFormField(){
    return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
}


public function setButton( $ButtonValue , $ButtonName ){
    $this->_ButtonValue = $ButtonValue;
    $this->_ButtonName = $ButtonName;
}

public function getButton(){
    return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
}

public function getTagEnd(){
    return '</form>' . PHP_EOL;
}

}

$objForm = new cForm( '/' , 'post' , 'test' , 'onsubmit="test"' ); echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2'); echo $objForm->getFormField();

echo $objForm->setButton('test value','test name'); echo $objForm->getButton();

echo $objForm->getTagEnd();

I am new at OOP and i wonder if the code below is OOP or it can be better and also what can be better? Kr Bas

private $_TagAction;
private $_TagMethod;
private $_TagName;
private $_TagExtraAttr;

//var form field
private $_FieldType;
private $_FieldName;

//var button
private $_ButtonValue;
private $_ButtonName;

public function __construct( $_TagAction , $_TagMethod , $_TagName , $_TagExtraAttr ){
    $this->_TagAction = $_TagAction;
    $this->_TagMethod = $_TagMethod;
    $this->_TagName = $_TagName;
    $this->_TagExtraAttr = $_TagExtraAttr;
    
}

public function getTagOpen(){
    return '<form action="' . $this->_TagAction . '" method="' . $this->_TagMethod . '" name="' . $this->_TagName .'" ' . $this->_TagExtraAttr . '>' . PHP_EOL;
}

public function setFormField( $FieldType , $FieldName ){
    $this->_FieldType = $FieldType;
    $this->_FieldName = $FieldName;
}    

public function getFormField(){
    return '<input type="' . $this->_FieldType . '" name="' . $this->_FieldName . '" >'. PHP_EOL;
}


public function setButton( $ButtonValue , $ButtonName ){
    $this->_ButtonValue = $ButtonValue;
    $this->_ButtonName = $ButtonName;
}

public function getButton(){
    return '<input type="submit" value="' . $this->_ButtonValue . '" name="'. $this->_ButtonName .'">';
}

public function getTagEnd(){
    return '</form>' . PHP_EOL;
}

}

$objForm = new cForm( '/' , 'post'  , 'test' , 'onsubmit="test"' );
echo $objForm->getTagOpen();

echo $objForm->setFormField('text','2');
echo $objForm->getFormField();

echo $objForm->setButton('test value','test name');
echo $objForm->getButton();

echo $objForm->getTagEnd();
Source Link
Loading