【发布时间】:2015-10-23 17:09:12
【问题描述】:
我之前的问题已经解决,它谈到了 CodeIgniter 中的 base_url 重复。但是,将 base_url() 编辑为 base_url = "http://example.com/myapp/" 后,表单提交不会加载我的感谢页面。我已经用 Firebug 进行了检查,有一个 Response: 200 OK 来了。但是无论我做什么,我的视图 register-done.php 都不会加载。表格只是停留在那里。不动,但数据进入数据库并注册。在此修复之前,它工作正常。这是表单提交的html:
<div class="section-title">Personal Details</div>
<form id="profile-image-form" method="post" action="<?= base_url() ?>signup" enctype="multipart/form-data">
<img src="<?= asset_url() ?>css/images/grey-bg.png" width="128" class="profile-pic"/>
<button type="button" id="upload-supplier-user-image-button" class="no-btn-style" onclick="$('#profile_image').click()">Upload User Image</button>
<img style="display:none; width: 35px;" src="<?= asset_url()?>images/upload-loading.gif" id="supplier-profile-upload-gif"/>
<input type="file" name="image" id="profile_image" style="display: none"/>
</form>
<form id="register-company-form" method="post" action="<?= base_url() ?>signup/supplier" enctype="text/plain">
<input type="hidden" name="image" id="image" value=""/>
<input type="text" id="first_name" name="first_name" class="text-field"/>
<input type="text" id="last_name" name="last_name" class="text-field"/>
<input type="text" id="user_name" name="user_name" class="text-field"/>
<input type="email" id="personal_email" name="personal_email" class="text-field"/>
<input type="password" id="password" name="password" class="text-field"/>
<input type="password" id="confirm_password" name="confirm_password" class="text-field"/>
<input type="text" id="job" name="job" class="text-field"/>
<input type="submit" name="sign-up-personal" id="sign-up-personal" class="btn-purple supplier-login-btn" value="Sign Up"/>
<input type="text" id="company_name" name="company_name" class="text-field"/>
<input type="text" id="address_one" name="address_one" class="text-field"/>
<input type="text" id="address_two" name="address_two" class="text-field"/>
<input id="autocomplete" placeholder="Enter your city" type="text" class="text-field" required autocomplete="off"/>
<input id="city" type="hidden" value="" name="city" required>
<input id="country" type="hidden" value="" name="country" required>
<button type="button" class="btn-purple supplier-login-btn" onclick="$('#company_logo_file').click()">Browse</button>
<input type="hidden" id="company_logo" name="company_logo" value=""/>
<textarea id="company_description" name="company_description" class="textarea-field"></textarea>
<input type="text" id="company_website" name="company_website" class="text-field"/>
<input type="email" id="company_email" name="company_email" class="text-field"/>
<input type="text" id="company_telephone" name="company_telephone" class="text-field"/>
<button type="button" class="btn-purple supplier-login-btn" onclick="$('#trade_license').click()">Browse</button>
<input type="file" id="trade_license" name="trade_license" class="text-field hidden" accept="application/pdf"/>
<input type="checkbox" name="terms" value="yes"/> By Signing up, I agree to <span class="terms-of-service">terms of service</span>
<input type="submit" name="sign-up" id="sign-up" class="btn-purple supplier-login-btn" value="Sign Up"/>
</form>
<form id="company_logo_form" method="post" action="" enctype="multipart/form-data">
<input type="file" style="display: none" name="company_logo_file" id="company_logo_file" accept="image/*"/>
</form>
<script type="text/javascript">
$.validator.addMethod("valueNotEquals", function(value, element, arg){
return arg != value;
}, "Value must not equal arg.");
var validator = $('#register-company-form').validate({
/* some validation */
submitHandler: function(form) {
var formData = new FormData($(form)[0]);
$.ajax({
type: $(form).attr('method'),
url: $(form).attr('action'),
data: formData,
dataType : 'json',
cache: false,
contentType: false,
processData: false
})
.done(function (response) {
window.location.href = '<?= base_url() ?>supplier/successful';
});
});
</script>
这里是注册控制器。我什么都没做,但它停止向数据库发送表单:(任何帮助将不胜感激。@DFriend
<?php
class Signup extends CI_Controller {
private $return_data = NULL;
private $return_status = 200;
private $return_message = NULL;
public function index(){
$this->load->model('CaptchaModel');
$this->load->helper('Captcha');
$cid = $this->input->post('cid');
$captcha = $this->input->post('captcha');
$captcha_exist = $this->CaptchaModel->check_captcha($captcha, $cid);
if($captcha_exist)
{
$this->load->model('RegisterModel');
$image = parent::check_user_input($this->input->post('image'));
$title = $this->input->post('title');
$first_name = $this->input->post('first_name');
$last_name = $this->input->post('last_name');
$user_name = $this->input->post('user_name');
$email = $this->input->post('email');
$password = $this->input->post('password');
$gender = $this->input->post('gender');
$mobile = parent::check_user_input($this->input->post('mobile'));
$dob_day = parent::check_user_input($this->input->post('dob_day'));
$dob_month = parent::check_user_input($this->input->post('dob_month'));
$dob_year = parent::check_user_input($this->input->post('dob_year'));
if($dob_day != '' && $dob_month != '' && $dob_year != ''){
$date_of_birth = new DateTime($dob_year . '-' . $dob_month . '-' . $dob_day);
}
else
{
$date_of_birth = '';
}
$country = parent::check_user_input($this->input->post('country'));
$city = parent::check_user_input($this->input->post('city'));
$interests = $this->input->post('interests');
$habits = $this->input->post('habits');
$comment = parent::check_user_input($this->input->post('comments'));
$newsletter = parent::check_user_input($this->input->post('newsletter'));
$registration = $this->RegisterModel->register($image, $title, $first_name, $last_name, $user_name, $email, $password, $mobile, $date_of_birth, $country, $city, $interests, $habits, $comment, $newsletter, $gender);
if($registration == -1)
{
$this->return_status = 400;
parent::returnJson($this->return_data, $this->return_status, $this->return_message);
}
elseif
($registration == -2)
{
$this->return_status = 401;
parent::returnJson($this->return_data, $this->return_status, $this->return_message);
}elseif
($registration){
$this->load->library('session');
$user_data = array('login' => 1,'uid' => $registration);
$this->session->set_userdata($user_data);
parent::returnJson($this->return_data, $this->return_status, $this->return_message);
}
else
{
$this->return_status = 500;
parent::returnJson($this->return_data, $this->return_status, $this->return_message);
}
}
else
{
$this->return_status = 600;
parent::returnJson($this->return_data, $this->return_status, $this->return_message);
}
}
public function supplier()
{
$file_element_name = 'trade_license';
$this->load->model('RegisterModel');
$profile_image_form = $this->input->post('image');
$title = $this->input->post('title');
$first_name = $this->input->post('first_name');
$last_name = $this->input->post('last_name');
$user_name = $this->input->post('user_name');
$email = $this->input->post('personal_email');
$password = $this->input->post('password');
$job = $this->input->post('job');
$company_name = $this->input->post('company_name');
$address_one = $this->input->post('address_one');
$address_two = $this->input->post('address_two');
$country = $this->input->post('country');
$city = $this->input->post('city');
$company_description = $this->input->post('company_description');
$company_website = $this->input->post('company_website');
$company_email = $this->input->post('company_email');
$company_telephone = $this->input->post('company_telephone');
$company_logo = $this->input->post('company_logo');
$trade_license = '';
$config['upload_path'] = './assets/license/';
$config['allowed_types'] = 'pdf';
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($file_element_name))
{
$status = 'error';
$msg = $this->upload->display_errors('', '');
}
else
{
$data = $this->upload->data();
$status = "success";
$msg = '';
$trade_license = $data['file_name'];
}
$profile_image = $profile_image_form;
$config['upload_path'] = './assets/profile/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($profile_image_form))
{
$status = 'error';
$msg = $this->upload->display_errors('', '');
}
else
{
$data = $this->upload->data();
$status = "success";
$msg = '';
$profile_image = $data['file_name'];
}
$email_found = $this->db->get_where("supplier_user", array("company_email" => $email));
if($email_found->result_id->num_rows > 0) {
parent::returnJson($this->return_data, 401, $this->return_message);
}
else
{
$email_found_2 = $this->db->get_where("supplier_user", array("email" => $email));
if($email_found_2->result_id->num_rows > 0) {
parent::returnJson($this->return_data, 402, $this->return_message);
}
else
{
$username_found = $this->db->get_where("supplier_user", array("user_name" => $user_name));
if($username_found->result_id->num_rows > 0) {
parent::returnJson($this->return_data, 403, $this->return_message); }
else
{
$this->RegisterModel->register_supplier($profile_image, $title, $first_name, $last_name, $user_name, $email, $password, $job, $company_name, $address_one, $address_two, $country, $city, $company_description, $company_website, $company_email, $company_telephone, $company_logo, $trade_license);
parent::returnJson($this->return_data, $this->return_status, $this->return_message);
}
}
}
}
}
【问题讨论】:
-
我相信
$config['base_url']需要将域和路径指向您的安装。 IE。$config['base_url'] = 'www.example.com'使用您的 .htaccess 条目,我认为您不需要添加路径。尝试使用和不使用'/myapp/" -
哇。了不起的@DFriend 这部作品很有魅力。你是一个救生员。自从我尝试这个有多久以来,我做了所有可能的事情。但这有效。谢谢你,我的朋友。
-
但现在我有另一个问题。我的用户注册视图加载,但在输入数据后没有做任何事情。它在此更改之前有效。我不知道怎么了!有什么帮助吗?
-
需要查看更多代码才能发表评论。特别是处理提交的控制器/函数。表单 html 也不会受到伤害。
-
使用此代码编辑您的问题。没有人可以这样处理。
标签: .htaccess codeigniter mod-rewrite codeigniter-3