Codeigniter File upload validation undefined index - php

I don't know where I got wrong but I couldn't find it out.
I have a form validation with a callback file check validation function
My Add_Post Function:
public function add_post()
{
$validation = array (
array(
'field' => 'post_title',
'label' => 'Post title',
'rules' => 'trim|required|alpha_numeric'
),
array(
'field' => 'headerimage',
'rules' => 'required|callback_file_check'
),
array(
'field' => 'post_desc',
'label' => 'Post Description',
'rules' => 'trim|required|alpha_numeric'
),
array(
'field' => 'post_content',
'label' => 'Post content',
'rules' => 'trim|required'
)
);
$this->form_validation->set_rules($validation);
if($this->form_validation->run()===FALSE)
{
$info['errors'] = validation_errors();
$info['success'] = false;
}
else
{
$config = array(
"upload_path" => "./uploads/blog_images",
"max_size" => "2048000",
"allowed_types"=> "gif|png|jpg|jpeg",
"file_name" => 'header_'.substr(md5(rand()),0,7),
"overwrite" => false
);
$this->load->library('upload', $config);
if($this->upload->do_upload('file'))
{
$uploadFile = $this->upload->upload_data();
$uploadFileName = $uploadFile['file_name'];
$data = array(
"post_title" => $this->input->post('post_title'),
"post_content" => $this->input->post('post_content'),
"post_image" => $uploadFileName,
"post_created" => $this->input->post('time')
);
$this->Blog_model->add_post($data);
}
$info['success'] = true;
$info['message'] = "Successfully added blog post";
}
$this->output->set_content_type('application/json')->set_output(json_encode($info));
}
Callback function:
public function file_check($str){
$allowed_mime_type_arr = array('application/pdf', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
$mime = get_mime_by_extension($_FILES['headerimage']['name']);
if(isset($_FILES['headerimage']['name']) && $_FILES['headerimage']['name'] != "") {
if(in_array($mime, $allowed_mime_type_arr)) {
return true;
} else {
$this->form_validation->set_message('file_check', 'Please select only pdf/gif/jpg/png file.');
return false;
}
} else {
$this->form_validation->set_message('file_check', 'Please choose a file to upload.');
return false;
}
}
Here's for the view part:
<?php echo form_open_multipart('Blog/file_check',array("class"=>"form-horizontal","id"=>"blogform")); ?>
<div class="row">
<div class="col-md-6">
<input type="text" placeholder="Enter your post title" name="post_title" class="form-control">
</div>
<div class="col-md-6 form-group">
<label for="file" class="control-label col-md-4">Select header image:</label>
<div class="col-md-8">
<input type="file" name="headerimage" id="file" accept="image/*" />
</div>
</div>
</div>
<input type="text" placeholder="Enter your post description" name="post_desc" class="form-control">
<label class="control-label text-muted">Post Body:</label>
<div>
<textarea id="post_content" name="content"></textarea>
</div>
<button class="btn btn-default pull-right" type="button" id="save-post"><i class="fa fa-save"></i> Save Post</button>
<div class="clearfix"></div>
<?php echo form_close(); ?>
My Ajax code:
$(document).on('click','#save-post',function(){
$post_content = $('#post_content').summernote('code');
$time = $('#time').text();
$.ajax({
url:site_url('Blog/add_post'),
data: $('#blogform').serialize() + "&post_content=" + $post_content + "&time=" + $time,
type: "POST",
dataType: 'json',
encode: true,
success: function(data){
if(!data.success) {
if(data.errors) {
$('#blog-message').html(data.errors).addClass('alert alert-danger');
}
} else {
alert(data.message);
}
}
});
});
Input FileName Checked: I already checked the input name and it's the same.
Image Size: I checked for some related question of mine which is undefined index on file validation and they said image size must be big but I use a small size image sample.
I used Krajee's File Input Plugin.

Related

Can't insert checkbox data in sql database ( not stored or null in database ) - using codeigniter

As per question title i can't manage to insert checkbox data into database
Here is my model
public function rules() {
return array(
array( 'field' => '_butype_',
'label' => 'Business Type',
'rules' => 'required|trim|alpha_numeric_spaces|min_length[2]|max_length[50]'),
array( 'field' => '_bumotiv_[]',
'label' => 'Motivation',
'rules' => 'required'),
);
}
public function getById($id){
return $this->db->get_where($this->table, array($this->primary => $id) )->row_array();
}
public function getAll() {
return $this->db->get($this->table)->result_array();
}
public function insert(){
$post = $this->input->post();
if (!empty($post)){
$data = array(
'ginfo_id' => NULL,
'ginfo_butype' => htmlspecialchars($post['_butype_']),
'ginfo_bumotiv' => json_encode($$post['_bumotiv_[]']),
);
$data = $this->security->xss_clean($data);
if($this->db->insert($this->table, $data)){
$response = array(
'status' => 'success',
'message' => 'Success insert data',
);
} else {
$response = array(
'status' => 'error',
'message' => 'Failed insert data',
);
}
} else {
$response = array(
'status' => 'error',
'message' => 'Data not found!',
);
}
return $response;
}
Here is my Controller
public function add(){
$this->form_validation->set_rules($this->M_Ginfo->rules());
if ($this->form_validation->run() === TRUE) {
$this->session->set_flashdata('notif', $this->M_Ginfo->insert());
redirect(site_url('admin/ginfo/add'),'refresh');
} else {
$data['notif'] = $this->M_Auth->notification();
$this->load->view('admin/ginfo/add.php', $data);
}
}
Here is my model
<div class="form-group row">
<label for="_bumotives_[]" class="col-sm-3 col-form-label" style="text-align: left;">What actually motivated you to start your own business? </label>
<div class="col-sm-6">
<input class="form-group" type="checkbox" name="_bumotiv_[]" id="_bumotiv_[]" value="To be independent from working for other people" <?php echo set_checkbox('bumotiv_[]', 'To be independent from working for other people', false); ?>>
<label for="_bumotiv_[]" >To be independent from working for other people. </label>
<br>
<input class="form-group" type="checkbox" name="_bumotiv_[]" id="_bumotiv_[]" value="I have a bright idea that can be commercialised" <?php echo set_checkbox('bumotiv_[]', 'I have a bright idea that can be commercialised', false); ?>>
<label for="_bumotiv_[]" >I have a bright idea that can be commercialised.</label>
<br>
</div>
There are other data that got insert successfully only checkbox is the only form field that has not been submitted to the database
I tried many solution but non worked for me
Any help is appreciated
If non of the checkbox is selected you will not get any result for checkbox.
Check your code for insert query there is an extra $
'ginfo_bumotiv' => json_encode($$post['_bumotiv_[]']),

Codeigniter form-validation is always returning false

I am trying to get form values and passing it in my model to store in the database. Whenever I end up submitting the form, I always get the values as NULL.
form.php
<form action="http://localhost/hbp/review/submit/" method="post">
<input type="hidden" name='<?php echo $this->security->get_csrf_token_name(); ?>' value='<?php echo $this->security->get_csrf_hash(); ?>'>
<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<!-- <input type="text" name="title">-->
<?php echo form_input(['id' => 'title', 'name' => 'title', 'class' => 'form-control', 'placeholder' => 'Enter your review title']); ?>
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Review</label>
<!-- <textarea rows="10" cols="100" name="message"></textarea>-->
<?php echo form_textarea(['id' => 'message', 'name' => 'message', 'class' => 'form-control', 'placeholder' => 'Enter your review title', 'rows' => '10', 'cols' => '100']); ?>
</div>
<button name="submit">Hello</button>
</form>
I have tried using both form_input() and simple HTML syntax for rendering form fields. None of them worked.
controller.php
if ($gClient->getAccessToken()) {
$userProfile = $google_oauthV2->userinfo->get();
$name = $userProfile['name'];
$email = $userProfile['email'];
$picture = $userProfile['picture'];
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'title', 'required');
$this->form_validation->set_rules('message', 'message', 'required');
if ($this->form_validation->run() == FALSE){
echo "error in your form ";
$this->session->set_flashdata('review_error', 'Please fill all the fields!');
$this->load->view('pages/review');
} else {
$this->session->set_flashdata('review_success', 'Thank you for you ');
$this->review_model->set_review($name, $email, $picture);
redirect(base_url() . 'review/');
}
echo "just dies";
model.php
class Review_model extends CI_Model
{
public function set_review($google_name, $google_email, $google_image)
{
$data = array('review_title' => $this->input->post('title'),
'review_content' => $this->input->post('message'),
'email' => $google_email,
'name' => $google_name,
'image_url' => $google_image);
return $this->db->insert('reviews', $data);
}
public function get_review(){
$query = $this->db->get('reviews');
return $query->result_array();
}
}
I keep getting the review_title can't be NULL.

Upload image error not hide even i upload image

I do form validation in backend in codeigniter, on clientside every field alrets work fine but on image field the error persist even i attach the image... below is my code and i am attaching image screenshort for further detail. Please help in this regards.
Here is My Controller code
public function save(){
$res = array();
//form field validation rules
$this->form_validation->set_rules('titlemaster', 'Main Title', 'required');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'Ourpeople Main Title Required'));
exit;
}
$this->form_validation->set_rules('detailmaster', 'Main Detail', 'required');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'Oupeople Main Description Required'));
exit;
}
$config['upload_path'] = 'fassets/images/oupeople';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['userfile']['name'];
$config['overwrite'] = TRUE;
//Load upload library and initialize configuration
$this->load->library('upload', $config);
$ourpeoplesection = ($this->input->post('name')) . ($this->input->post('desig')) . ($this->input->post('aboutme')) . ($this->input->post('certification')) . ($this->upload->do_upload('userfile'));
if (!empty($ourpeoplesection))
{
$this->form_validation->set_rules('name', 'Name', 'required|max_length[25]');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'Name Required'));
exit;
}
$this->form_validation->set_rules('desig', 'Designation', 'required|max_length[20]');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'Designation Required'));
exit;
}
$this->form_validation->set_rules('aboutme', 'About Employee', 'required');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'About Employee Required'));
exit;
}
$this->form_validation->set_rules('certification', 'Certification', 'required');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'Certification Required'));
exit;
}
if(!$this->upload->do_upload('userfile'))
{
$error = 'Please upload Image file. <br>';
//$error = $this->upload->display_errors('', '<br>');
echo json_encode(array('mes' => 'alert-danger', 'msg' => $error));
exit;
}
$userData = array (
'name' => $this->input->post('name'),
'desig' => $this->input->post('desig'),
'aboutme' => $this->input->post('aboutme'),
'certification' => $this->input->post('certification'),
'facebook' => $this->input->post('facebook'),
'twitter' => $this->input->post('twitter'),
'instagram' => $this->input->post('instagram'),
'google' => $this->input->post('google'),
'userfile' => $this->upload->data('file_name'),
);
//Pass user data to model
$insertData = $this->Ourpeoplemodel->insert($userData);
}
$ourpeopleMaster = array(
'titlemaster' => $this->input->post('titlemaster') ,
'detailmaster' => $this->input->post('detailmaster')
);
$insertUserData = $this->Ourpeoplemodel->insert_main($ourpeopleMaster);
//Storing insertion status message.
if(($insertUserData && $insertData)){
$res = array(
'mes' => 'text-success',
'msg' => "Record has been saved successfully.",
);
echo json_encode($res);
} else {
$res = array(
'mes' => 'text-danger',
'msg' => "Record not saved",
);
echo json_encode($res);
}
}
here my html input
<div class="form-group row">
<div class="col-md-6 col-xs-12">
<?php if(isset($ourpeople_master)){;?>
<input type="text" class="form-control input-sm" name="titlemaster" value="<?php echo set_value('titlemaster', $ourpeople_master->titlemaster);?>" placeholder="Main Title | max 25 characters" required="required">
</div>
<div class="col-md-6 col-xs-12">
<input type="text" class="form-control input-sm" name="detailmaster" value="<?php echo set_value('detailmaster', $ourpeople_master->detailmaster);?>" placeholder="Main Decription." required="required">
</div>
<?php }?>
</div>
<div class="form-group row">
<div class="col-md-4 col-xs-12">
<input type="text" class="form-control input-sm" name="name" value="" placeholder="Name Required">
</div>
<div class="col-md-4 col-xs-12">
<input type="text" class="form-control input-sm" name="desig" value="" placeholder="Designation Required">
</div>
<div class="col-md-4 col-xs-12">
<input type="file" name="userfile" class="form-control input-sm">
</div>
</div>
<div class="form-group row">
<div class="col-md-12 col-sm-12">
<textarea name='aboutme' rows="1" class='form-control input-sm' placeholder="About Employee Detail"></textarea>
</div>
</div>
<div class="form-group row">
<div class="col-md-12 col-sm-12">
<textarea name='certification' rows="1" class='form-control input-sm' placeholder="Employee's Certifications Detail"></textarea>
</div>
</div>
<div class="form-group row">
<div class="col-md-3 col-xs-12">
<input type="text" class="form-control input-sm" name="facebook" placeholder="Facebook Profile Link Here">
</div>
<div class="col-md-3 col-xs-12">
<input type="text" class="form-control input-sm" name="twitter" placeholder="Twitter Profile Link Here">
</div>
<div class="col-md-3 col-xs-12">
<input type="text" class="form-control input-sm" name="instagram" placeholder="Instagram Profile Link Here">
</div>
<div class="col-md-3 col-xs-12">
<input type="text" class="form-control input-sm" name="google" placeholder="Google Plus Profile Link Here">
</div>
</div>
<div class="form-group row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-success btn-sm" id="save"><i class="fa fa-save"></i> Save</button>
</div>
</div>
I think you got confused by my last answer - you can use $_FILES['userfile']['name'] you just have to wrap it in isset or in this case empty otherwise notices will fire (and affect your json response) if the file isn't uploaded.
$config['upload_path'] = 'fassets/images/oupeople';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
//$config['file_name'] = $_FILES['userfile']['name'];
$config['overwrite'] = TRUE;
//Load upload library and initialize configuration
$this->load->library('upload', $config);
//$ourpeoplesection = ($this->input->post('name')) . ($this->input->post('desig')) . ($this->input->post('aboutme')) . ($this->input->post('certification')) . ($this->upload->do_upload('userfile'));
if (!empty($_FILES['userfile']['name']))
{
$this->form_validation->set_rules('name', 'Name', 'required|max_length[25]');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'Name Required'));
exit;
}
$this->form_validation->set_rules('desig', 'Designation', 'required|max_length[20]');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'Designation Required'));
exit;
}
$this->form_validation->set_rules('aboutme', 'About Employee', 'required');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'About Employee Required'));
exit;
}
$this->form_validation->set_rules('certification', 'Certification', 'required');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => 'Certification Required'));
exit;
}
if(!$this->upload->do_upload('userfile'))
{
$error = 'Please upload Image file. <br>';
//$error = $this->upload->display_errors('', '<br>');
echo json_encode(array('mes' => 'alert-danger', 'msg' => $error));
exit;
}
$userData = array (
'name' => $this->input->post('name'),
'desig' => $this->input->post('desig'),
'aboutme' => $this->input->post('aboutme'),
'certification' => $this->input->post('certification'),
'facebook' => $this->input->post('facebook'),
'twitter' => $this->input->post('twitter'),
'instagram' => $this->input->post('instagram'),
'google' => $this->input->post('google'),
'userfile' => $this->upload->data('file_name'),
);
//Pass user data to model
$insertData = $this->Ourpeoplemodel->insert($userData);
}
I would also like to suggest instead of having many different form validation conditions just have one...
$this->form_validation->set_rules('name', 'Name', 'required|max_length[25]');
$this->form_validation->set_rules('desig', 'Designation', 'required|max_length[20]');
$this->form_validation->set_rules('aboutme', 'About Employee', 'required');
$this->form_validation->set_rules('certification', 'Certification', 'required');
if (!$this->form_validation->run()) {
echo json_encode(array('mes' => 'text-danger', 'msg' => validation_errors()));
exit;
}

Upload issue in Codeigniter with image and text/numbers

First of all sorry for the long post with code, but i feel like i need to explain myself straight. The issue is, i'm trying to insert some data into a database and also the file name in the RESTAURANT_IMAGE column. Everything inserts perfectly fine but the image doesn't upload and the file name is not inserted into the database.
EDIT: Edited the callback function to properly return True or False and now i do the insert in the main function if the callback returns true.
Now i am able to upload the image successfully but still dont get the file name and extension to put into my database.
function restaurant_add()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$config = array(
array(
'field' => 'RestaurantName',
'label' => 'Restaurant Name',
'rules' => 'required|callback_restaurant_check'
),
array(
'field' => 'RestaurantAddress',
'label' => 'Address',
'rules' => 'required'
),
array(
'field' => 'RestaurantReservations',
'label' => 'Reservations',
'rules' => 'max_length[1]|integer'
),
array(
'field' => 'RestaurantWifi',
'label' => 'RestaurantWifi',
'rules' => 'max_length[1]|integer'
),
array(
'field' => 'RestaurantDelivery',
'label' => 'Restaurant Delivery',
'rules' => 'max_length[1]|integer'
),
array(
'field' => 'RestaurantMultibanco',
'label' => 'RestaurantMultibanco',
'rules' => 'max_length[1]|integer'
),
array(
'field' => 'RestaurantImage',
'label' => 'RestaurantImage',
'rules' => ''
)
);
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE)
{
$this->load->view('sample_navbar_view');
$this->load->view('restaurant_add');
return FALSE;
}
else
{
$file_name = $this->do_upload();
$data = array(
'RESTAURANT_NAME' => $this->input->post('RestaurantName'),
'RESTAURANT_ADDRESS' => $this->input-> post('RestaurantAddress'),
'RESTAURANT_RESERVATIONS'=> $this->input-> post('RestaurantReservations'),
'RESTAURANT_WIFI'=> $this->input-> post('RestaurantWifi'),
'RESTAURANT_DELIVERY'=> $this->input-> post('RestaurantDelivery'),
'RESTAURANT_MULTIBANCO'=> $this->input-> post('RestaurantMultibanco'),
'RESTAURANT_OUTDOOR_SEATING'=> $this->input-> post('RestaurantOutdoorSeating'),
'RESTAURANT_IMAGE'=> $file_name
);
$this->load->model('restaurant_model');
$this->restaurant_model->restaurant_add($data);
return TRUE;
}
}
Callback function to check if the restaurant name exists, if it does, it doesn't register it, if it doesn't sends the data into the model.
function restaurant_check($restaurantname){
$this->load->model('restaurant_model');
$result = $this->restaurant_model->check_restaurant_name($restaurantname);
if($result > 0) {
return FALSE;
}
else {
return TRUE;
}
}
I used the upload file article present in the Codeigniter Documentation.
View Code:
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<?php echo form_open_multipart('restaurant/restaurant_add');?>
<form name="restaurant_add" method="post" action="<?php echo site_url().'Restaurant/restaurant_add'; ?>">
<h2>Register your Restaurant</h2>
<input class="form-control" type="text" class="user" name="RestaurantName" placeholder="Restaurant Name">
<input class="form-control"type="text" class="pass" name="RestaurantAddress" placeholder="Restaurant Address">
<input class="form-control"type="number" class="numero" name="RestaurantReservations" placeholder="Restaurant Rerservations">
<input class="form-control"type="number" class="numero" name="RestaurantWifi" placeholder="Wi-Fi">
<input class="form-control"type="number" class="numero" name="RestaurantDelivery" placeholder="Home Deliveries">
<input class="form-control"type="number" class="numero" name="RestaurantMultibanco" placeholder="Have Multibanco?">
<input class="form-control"type="number" class="numero" name="RestaurantOutdoorSeating" placeholder="Esplanada">
<input class="form-control"type="file" class="image" name="RestaurantImage" placeholder="Upload a Picture">
<div class="container">
<?php echo validation_errors(); ?>
</div>
<button class="btn btn-danger"type="submit">Registar</button>
</form>
</div>
</div>
EDIT: Model Code:
function restaurant_add($info)
{
$query =
"INSERT INTO RESTAURANTS
(RESTAURANT_NAME,RESTAURANT_ADDRESS,RESTAURANT_RESERVATIONS,
RESTAURANT_WIFI,RESTAURANT_DELIVERY,RESTAURANT_MULTIBANCO,
RESTAURANT_OUTDOOR_SEATING,RESTAURANT_IMAGE
)
VALUES
(
'".$info['RESTAURANT_NAME']."',
'".$info['RESTAURANT_ADDRESS']."',
'".$info['RESTAURANT_RESERVATIONS']."',
'".$info['RESTAURANT_WIFI']."',
'".$info['RESTAURANT_DELIVERY']."',
'".$info['RESTAURANT_MULTIBANCO']."',
'".$info['RESTAURANT_OUTDOOR_SEATING']."',
'".$info['RESTAURANT_IMAGE']."'
)
";
$result = $this->db->query($query);
return TRUE;
}
function check_restaurant_name($restaurantname) {
$this->db->trans_begin();
$query = "SELECT RESTAURANT_NAME FROM RESTAURANTS WHERE RESTAURANT_NAME = '".$restaurantname."'";
$result = $this->db->query($query);
$rows = $result->num_rows();
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
}
return $rows;
}
do_upload() function:
public function do_upload()
{
$config['upload_path'] = './assets/images/restaurantes';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('success_view', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
$upload_data = $this->upload->data();
//Returns array of containing all of the data related to the file you uploaded.
$file_name = $this->upload->file_name;
return $file_name;
}

Codeigniter form_validation always return false

i try to validate my form, but it always return with FALSE. The form fill the POST variable, the validation config is setted up, but it don't work. I tried everything, and now i stucked. Maybe your eyes catch the error.
Here is my controller:
public function new_pass()
{
$code = mysql_real_escape_string($this->uri->segment(3));
$this->load->model('forgot_password_model');
if($this->forgot_password_model->check_code($code))
{
if($this->input->post('submit'))
{
$this->new_pass_validation();
}
else
{
$this->new_pass_form();
}
}
else
{
redirect('welcome');
}
}
private function new_pass_validation()
{
$this->load->library('form_validation');
var_dump($this->form_validation->run('forgot_password/new_pass'));
var_dump($this->input->post());
if ($this->form_validation->run() === FALSE)
{
// print_r('dump' . validation_errors());
$this->new_pass_form();
}
else
{
}
}
The config/form_validation:
$config = array(
'forgot_password/new_pass' => array(
array(
array(
'field' => 'password',
'label' => lang('default_jelszo'),
'rules' => 'trim|required|min_length[5]|max_length[32]'
),
array(
'field' => 'repassword',
'label' => lang('default_jelszo_megerosites'),
'rules' => 'trim|required|matches[password]|callback_password_hash'
),
)
),
);
And the view:
<section id="content">
<a id="logo" href=""></a>
<?=validation_errors(); ?>
<div class="formwrapp">
<form action="<?=site_url() . $this->uri->uri_string(); ?>" method="post">
<h3>Forgot password</h3>
<ul>
<li>Pass</li>
<li><input type="password" value="" name="password" /></li>
<li>Repass</li>
<li><input type="password" value="" name="repassword" /></li>
<li> </li><li><input id="login" type="submit" value="Submit" name="submit" /></li>
</ul>
</form>
</div>
</section>
You have an unnecessary array in your config file, try:
$config = array(
'forgot_password/new_pass' => array(
array(
'field' => 'password',
'label' => lang('default_jelszo'),
'rules' => 'trim|required|min_length[5]|max_length[32]'
),
array(
'field' => 'repassword',
'label' => lang('default_jelszo_megerosites'),
'rules' => 'trim|required|matches[password]|callback_password_hash'
)
)
);
I think the best way to do the job as your is to follow this link ... i.e. without using config type but if u want to use config i think u had forgot to write the code ...
$this->form_validation->set_rules($config);
http://ellislab.com/codeigniter%20/user-guide/libraries/form_validation.html

Categories