[英]form action codeigniter does not find post data
i have a problem with a form in codeigniter. 我在codeigniter中的表单有问题。 i have tried different things but i can not find a solution.
我尝试了不同的方法,但找不到解决方案。
this is the form: 形式如下:
<form method="post" action="<?php echo base_url(); ?>cms/cms/newUser">
<div class="row">
<div class="col-md-3">
Naam:
</div>
<div class="col-md-9">
<input type="text" id="naam" name="username" />
</div>
</div>
<div class="row">
<div class="col-md-3">
E-mail:
</div>
<div class="col-md-9">
<input type="email" name="mail" id="email" />
</div>
</div>
<div class="row">
<div class="col-md-3">
Passwoord:
</div>
<div class="col-md-9">
<input type="password" name="pass" id="password" />
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<input type="submit" name="aanmaken" class="btn btn-block btn-info" value="aanmaken" />
</div>
</div>
in my controller i process the data coming from the form. 在我的控制器中,我处理来自表单的数据。 the controller is located at controllers/cms/cms.php
控制器位于controllers / cms / cms.php
class Cms extends MY_Controller
{
public function newUser()
{
if(isset($_POST))
{
echo "verwerk deze data <br>";
if(isset($_POST['username']))
{
echo 'naam is set!';
}
else {
echo 'naam is not set!';
}
$naam = $_POST['username'];
$mail = $_POST['email'];
$pass = $_POST['password'];
echo "naam: " . $naam . "<br>";
echo "mail: " . $mail . "<br>";
echo "pass: " . $pass . "<br>";
$time = new DateTime();
$time->setTimezone(new DateTimeZone ('Europe/Brussels'));
$tijd = $time->format('Y-m-d H:i:s');
include_once('application/libraries/PasswordHash.php');
$hasher = new PasswordHash(12,false);
$passwoord = $hasher->HashPassword($pass);
$gebruiker = new Gebruiker();
$gebruiker->naam = $naam;
$gebruiker->email = $mail;
$gebruiker->paswoord = $passwoord;
$gebruiker->laatsteLogin = $tijd;
$gebruiker->active = 0;
echo "coded pas" . $passwoord . "<br>";
}
else
{
echo "no post";
}
}
when i check my website and fill in the form i get 3 php error that the values that i put in the variable from the post does not exist. 当我检查我的网站并填写表格时,我得到了3 php错误,我从帖子中放入变量的值不存在。 also the if(isset) function says that the variable is not set.
if(isset)函数还说未设置变量。 i don't know why the form action doesn't work.
我不知道为什么表单动作不起作用。
i even tried the codeigniter way but it gave the same result. 我什至尝试了codeigniter方式,但结果相同。
$name = $this->input->post('username');
thanks for the help. 谢谢您的帮助。
you need to pass only controllername/func_name and keep your controller file in controller
dir then try in CI way 您只需要传递controllername / func_name并将控制器文件保存在
controller
dir中,然后以CI方式尝试
<?php echo form_open("cms/newUser");?>
<?php echo form_close();?>
or 要么
<form method="post" action="<?php echo base_url(); ?>cms/newUser">
Else you need to use routing
for this and tell to pick this controller on that route for this go to config/routes.php and add route like:- 否则,您需要为此使用
routing
,并告诉要在该路由上选择该控制器,然后转到config / routes.php并添加以下路由:
$route['cms'] = "cms/cms";
In the form tag 在表单标签中
<form method="post" action="<?php echo base_url(); ?>cms/cms/newUser">
cms
is the name of the controller and you have used it twice. cms
是控制器的名称,您已经使用了两次。 Try with 试试看
<form method="post" action="<?php echo base_url(); ?>cms/newUser">
HTML:
enter code here
<form method="post" action="<?php echo site_url(); ?>/cms/cms/newUser">
<div class="row">
<div class="col-md-3">
Naam:
</div>
<div class="col-md-9">
<input type="text" id="naam" name="username" />
</div>
E-mail: 电子邮件:
<div class="row">
<div class="col-md-3">
Passwoord:
</div>
<div class="col-md-9">
<input type="password" name="pass" id="password" />
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<input type="submit" name="aanmaken" class="btn btn-block btn-info" value="aanmaken" />
</div>
</div>
PHP:
class Cms extends MY_Controller
{
public function newUser()
{
if(isset($_POST))
{
echo "verwerk deze data <br>";
if($this->input->post('username'))
{
echo 'naam is set!';
}
else {
echo 'naam is not set!';
}
$naam = $this->input->post('username');
$mail = $this->input->post('mail');
$pass = $this->input->post('pass');
echo "naam: " . $naam . "<br>";
echo "mail: " . $mail . "<br>";
echo "pass: " . $pass . "<br>";
$time = new DateTime();
$time->setTimezone(new DateTimeZone ('Europe/Brussels'));
$tijd = $time->format('Y-m-d H:i:s');
include_once('application/libraries/PasswordHash.php');
$hasher = new PasswordHash(12,false);
$passwoord = $hasher->HashPassword($pass);
$gebruiker = new Gebruiker();
$gebruiker->naam = $naam;
$gebruiker->email = $mail;
$gebruiker->paswoord = $passwoord;
$gebruiker->laatsteLogin = $tijd;
$gebruiker->active = 0;
echo "coded pas" . $passwoord . "<br>";
}
else
{
echo "no post";
}
}
$this->input->post('') will check automatically not need of isset(). $ this-> input-> post('')将自动检查是否不需要isset()。 $this->input->post('') will take name not id
$ this-> input-> post('')将使用名称而不是id
try to load form helper and use this code 尝试加载表单助手并使用此代码
controller: 控制器:
$this->viewContent['form_action'] = base_url()."cms/cms/newUser"; $ this-> viewContent ['form_action'] = base_url()。“ cms / cms / newUser”; $this->load->view('your_view_page',$this->viewContent);
$ this-> load-> view('your_view_page',$ this-> viewContent);
view: echo form_open($form_action); 查看:echo form_open($ form_action);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.