I am into procedural programming and new to OOP. With the following code, I would like to print a message "Submitted successfully" on clicking submit button. But it is not happening. In the procedural programming I do something like isset($_POST[$name]). Here how to refer button name?
<?php
//myclass
class InsertData {
public $txtwidth;
public $txtheight;
public $txtname;
public $btnwidth;
public $btnheight;
public $btnname;
function setTextField($tw, $th, $tname) {
$this->txtwidth = $tw;
$this->txtheight =$th;
$this->txtname = $tname;
}
function setButton($bw, $bh, $bname) {
$this->btnwidth = $bw;
$this->btnheight =$bh;
$this->btnname = $bname;
}
function displayText() {
if(isset($_POST[$this->btnname])) {
echo "Submitted successfully";
}
}
function getTextField() {
$str = "<form name='inputform' action='#' method='post'>
<input type='text' name='".$this->txtname."' Style=width:".$this->txtwidth."px;height:".$this->txtheight."px><br><br>
<input type='submit' name='".$this->btnwidth."' Style=width:".$this->btnheight."px;height:".$this->btnname."px>
</form>";
return $str;
}
}
?>
My code
<?php
//my code
include "InsertData.php";
$txt = new InsertData();
$txt->setTextField(800,200,'yourname');
$txt->setButton(100, 200, 'click');
echo $txt->getTextField();
echo $txt->displayText();
?>