如何发送$this->uname
&控制器数据$this->email
到controller / ctrl_crud.php
create.php
<?php
include 'FullScreenLayout.php';
class index {
public $uname, $email;
public function get_data() {
if ( isset($_POST) ) {
$this->uname = $_POST['form_uname'];
$this->email = $_POST['form_email'];
}
}
public function createForm(){
$createHTML = <<<EOT
<form method="POST">
<div class="main_form">
<div class="md-form">
<input type="text" id="form_uname" name="form_uname" class="form-control" placeholder="User Name">
</div>
<div class="md-form">
<input type="text" id="form_email" name="form_email" class="form-control" placeholder="Email Address">
</div>
<button type="submit" class="btn btn-submit">Submit</button>
</div>
</form>
EOT;
return $createHTML;
}
}
$ObjFullScreenLayout = new FullScreenLayout();
$ObjIndex = new index();
$ObjIndex->get_data();
echo $ObjFullScreenLayout->header();
echo $ObjIndex->createForm();
echo $ObjFullScreenLayout->footer();
?>
控制器/ ctrl_crud.php
<?php
class ctrl_crud {
}
?>
答案 0 :(得分:1)
将这些数据发送到构造函数
include 'controller/ctrl_crud.php';
public function get_data() {
if ( isset($_POST) ) {
$this->uname = $_POST['form_uname'];
$this->email = $_POST['form_email'];
new ctrl_crud($this->uname, $this->email);
}
}
<强>控制器/ ctrl_crud.php 强>
class ctrl_crud {
function __construct($uname, $email){
// use uname and email here
}
}
答案 1 :(得分:0)
只需在表单中添加一个指向要发送数据的页面的操作,如下所示:
<form action="controller/ctrl_crud.php" method="post">