我有一个收集用户数据的注册表单, 姓名,电子邮件等,并将其发送到电子邮件。 但是,验证似乎不起作用。
我的问题是,当用户点击提交时,即使没有 键入任何内容,页面重定向到表单操作脚本页面,而不是仅执行该页面中的脚本。
欢迎任何帮助。 麦克
表格:
<?php
echo form_open('viewer_registration_email/signup_validation');
echo validation_errors();
$name_data = array(
'name' => 'viewerFirstName',
'id' => 'viewerFirstName',
'value' => $this->input->post('viewerFirstName'),
'placeholder' =>" First Name",
'class' => 'customInputFieldSmallHome'
);
$email_data = array(
'name' => 'viewerEmail',
'id' => 'viewerEmail',
'value' => $this->input->post('viewerEmail'),
'placeholder' =>" Your Email",
'class' => 'customInputFieldHome'
);
echo form_hidden('submit_viewer', 1);
echo '<span style="float:left">';
echo form_input($name_data);
echo '</span><br>';
echo form_input($email_data);
echo form_submit("submit", "", 'class="signUpBtn"');
echo form_close();
?>
控制器:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Viewer_registration_email extends CI_Controller {
public function index()
{
}
public function signup_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('viewerFirstName','First Name','required|trim');
$this->form_validation->set_rules('viewerEmail','Email','required|trim|valid_email');
if($this->form_validation->run())
{
$this->load->library('email', array('mailtype' => 'html'));
$this->email->from('register@mysite.com','My site Registration');
$this->email->to('mike@mysite.com');
$this->email->subject('New registered user');
$birthday = $this->input->post('viewerBirthDay')."/".$this->input->post('viewerBirthMonth') ."/".
$this->input->post('viewerBirthYear');
$message = '<div style="width:100%; height:35px; background-color:#558F61;"></div>
<br><br><br>
<h1> A new user has registered as a <span style="font-weight:bold">Viewer</span> on Your website.</h1>
<br><br><br>
<table style="border:none">
<tr>
<td>
<span style="font-weight:bold">Name: </span>
</td>
<td>
'.$this->input->post('viewerFirstName').'
</td>
</tr>
<tr>
<td>
<span style="font-weight:bold">Last name: </span>
</td>
<td>
'.$this->input->post('viewerLastName').'
</td>
</tr>
<tr>
<td>
<span style="font-weight:bold">Email: </span>
</td>
<td>
'.$this->input->post('viewerEmail').'
</td>
</tr>
</table>
<br><br><br><br>
<div style="width:100%; height:35px; background-color:#558F61;"></div>';
$this->email->message($message);
//send email to user
if($this->email->send()){
//echo "Email has been sent.";
$this->load->view('confirm_registration_email');
}else{
echo 'email failed!';
}
}else{
$this->load->view('home_main');
}
}
}