cakePHP validation errors not showing - validation

So basically I have a view action in my users controller where the user can modify his information(username,first name, last name, email..) this form sends to another update action which does the saving stuff, problem is that when I submit the form and one or more fields don't meet the validation rules it doesn't show underneath each fields but the data doesn't save and
$this->User->validationErrors
outputs the errors.
my update action (accessed after submiting the form on view.ctp)
view.ctp:
<?php
echo $this->Form->create('User', array(
'inputDefaults' => array(
'div' => 'form-group',
'wrapInput' => false,
'class' => 'form-control'
),
'class' => 'well',
'url'=>array('controller'=>'users','action'=>'update'),
'id'=>'info-form'
));
?>
<fieldset>
<legend>Personal Information</legend>
<?php
echo $this->Form->input('id', array('value' => $userinfo['User']['id']));
echo $this->Form->input('User.username', array(
'label' => 'Username',
'value'=>$userinfo['User']['username']
));
?>
<td><?php echo $this->Form->error('username'); ?></td>
<?php
echo $this->Form->input('User.email', array(
'label' => 'E-mail',
'value'=>$userinfo['User']['email']
));
?>
<?php
echo $this->Form->input('User.fname', array(
'label' => 'First name',
'value'=>$userinfo['User']['fname']
));
?>
<?php
echo $this->Form->input('User.lname', array(
'label' => 'Last name',
'value'=>$userinfo['User']['lname']
));
?>
<?php
echo $this->Form->submit('Update', array(
'div' => 'form-group',
'class' => 'btn btn-success'
));
?>
</fieldset>
<?php echo $this->Form->end(); ?>
update function:
function update() {
$this->autoRender = false;
$this->User->set($this->request->data);
if ($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Information updated Successfuly.'), 'alert', array(
'plugin' => 'BoostCake',
'class' => 'alert-success'), 'success');
return $this->redirect('/users/view/' . $this->request->data['User']['id']);
} else {
// $errors = $this->User->validationErrors; var_dump($errors);die;
$this->Session->setFlash(__('An error occured'), 'alert', array(
'plugin' => 'BoostCake',
'class' => 'alert-danger'), 'danger');
return $this->redirect('/users/view/' . $this->request->data['User']['id']);
}
} else {
$this->Session->setFlash(__('Request was not of POST type.'), 'alert', array(
'plugin' => 'BoostCake',
'class' => 'alert-danger'), 'danger');
return $this->redirect('/users/index/');
}

It's because you're redirecting after - that will make it lose the validation warnings.

Related

Codeigniter 3: Unknown column 'submit' in 'field list'

I am making a CRUD application with Codeignater 3.
I have an "Add Customers" form with First name, Last name, Email address, City and a submit button.
The model looks like this:
class Customer extends CI_Model {
public function saveCustomer($data) {
$tbl = $this->db->dbprefix('customers');
$this->db->insert($tbl, $data);
}
}
The controller:
if ($this->form_validation->run()) {
$data = $this->input->post();
$this->load->model('Customer');
if ($this->Customer->saveCustomer($data)) {
$this->session->set_flashdata('response','Customer successfully added');
} else {
$this->session->set_flashdata('response','Failed to save customer');
}
return redirect('home');
}
The View file:
<?php echo form_open('home/save'); ?>
<div class="form-group <?php if(form_error('first_name')) echo 'has-error';?>">
<?php echo form_input('first_name', '', [
'type' => 'text',
'id' => 'first_name',
'class' => 'form-control',
'value' => '',
'placeholder' => 'First name',
]);
?>
<?php echo form_error('first_name'); ?>
</div>
<div class="form-group <?php if(form_error('last_name')) echo 'has-error';?>">
<?php echo form_input('last_name', '', [
'type' => 'text',
'id' => 'last_name',
'class' => 'form-control',
'value' => '',
'placeholder' => 'Last name',
]);
?>
<?php echo form_error('last_name'); ?>
</div>
<div class="form-group <?php if(form_error('email')) echo 'has-error';?>">
<?php echo form_input('email', '', [
'type' => 'text',
'id' => 'email',
'class' => 'form-control',
'value' => '',
'placeholder' => 'Email address',
]);
?>
<?php echo form_error('email'); ?>
</div>
<div class="form-group">
<?php echo form_input('phone', '', [
'type' => 'text',
'id' => 'phone',
'class' => 'form-control',
'value' => '',
'placeholder' => 'Phone number',
]);
?>
</div>
<div class="form-group">
<?php echo form_input('city', '', [
'type' => 'text',
'id' => 'city',
'class' => 'form-control',
'value' => '',
'placeholder' => 'City',
]);
?>
</div>
<div class="form-group">
<?php echo form_input('address', '', [
'type' => 'text',
'id' => 'address',
'class' => 'form-control',
'value' => '',
'placeholder' => 'Address',
]);
?>
</div>
<div class="form-group">
<?php echo form_submit('submit', 'Save', 'class = "btn btn-primary btn-block"'); ?>
</div>
<?php echo form_close(); ?>
The problem:
When I submit the form I get this error: Unknown column 'submit' in 'field list'
Why is that?
Change your $data as follows:
$data = array('column_name1' => $this->input->post('first_name'),
'column_name2' => $this->input->post('last_name'),
'column_name3' => $this->input->post('email'),
'column_name4' => $this->input->post('phone'),
'column_name5' => $this->input->post('city'),
'column_name6' => $this->input->post('address'));
NOTE: There is no need of return in controller, only redirect('home') is needed.
Small change in controller
if ($this->form_validation->run()) {
$data = $this->input->post();
//unset your submit value which are come from submit btn
if(isset($data['submit'])){unset($data['submit'])}
if(isset($data->submit)){unset($data->submit)}
$this->load->model('Customer');
if ($this->Customer->saveCustomer($data)) {
$this->session->set_flashdata('response','Customer successfully added');
} else {
$this->session->set_flashdata('response','Failed to save customer');
}
return redirect('home');
}

Yii Refresh Grid On DropDown change

In YII views folder i have test module and admin.php file to manage contents are below and i render form here where i put the code of form and dropdown in it , i want that grid refresh value of status change in dropdown
Suppose i select "Approved" than Grid show the data where status is approved
<?php
Yii::app()->clientScript->registerScript('dropdown', "
$('.dropdown-form form').submit(function(){
$('#testimonial-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Testimonials</h1>
<div class="dropdown-form">
<?php $this->renderPartial('_dropdownform',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'testimonial-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'created_by',
'test_name',
'test_email',
'comments',
'created_at',
/*
'status',
'approved_on',
'approved_by',
*/
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Form below is _dropdownform , it contain a form and dropdown from this dropdown i am choosing the value of status
<div class="wide form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
));
?>
<div class="row">
<?php
echo CHtml::dropDownList('status', '', array(0 => 'New', 1 => 'Approved', 2 => 'Declined'), array(
'prompt' => 'Select Status',
'ajax' => array(
'type' => 'POST',
'url' => Yii::app()->createUrl('testimonial/loadthedata'),
//or $this->createUrl('loadcities') if '$this' extends CController
'update' => '#testimonial-grid', //or 'success' => 'function(data){...handle the data in the way you want...}',
'data' => array('status' => 'js:this.value'),
)));
?>
</div>
<div class="row buttons">
<?php //echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
AND THE CODE IN MY CONTROLLER OR URL GIVEN IN DROPDOWN TO FETCH DATA IS FOLLOWING ACTION BUT I DONT KNOW HOW TO FETCH DATA FROM THIS FUNCTION AND PASS TO GRID VIEW
public function actionloadthedata() {
if (isset($_POST['status'])) {
$status = $_POST['status'];
if($status==0){
$status='New';
}
if($status==1){
$status='Approved';
}
if($status==2){
$status='Declined';
}
Testimonial::model()->findByAttributes(array('status'=>$status));
}
}
You can use CGridView property filterCssClass to link the grid filter, for example
$this->widget('CGridView', array(
'id' => 'my-list',
'filterCssClass' => '#filterFormId .filter',
And there is filter form
<?php $form = $this->beginWidget('CActiveForm', array(
'id' => 'filter-fomr-id',
)); ?>
<div class="filter clearfix">
<?php echo $form->dropDownList($model, 'name', [0=>'all', '1'=>'some else']); ?>
</div>
Replace #filterFormId .filter on jquery selector specific to you form. In other words, set id attribute for filter form, then use "#THISID .row".
In your gridview file, make sure you have this code:
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#ad-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
then in the CGridView definition:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'testimonial-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
...
array(
'name'=>'Status',
'filter'=>CHtml::dropDownList('YourModel[status]', $model->status, array(0 => 'New', 1 => 'Approved', 2 => 'Declined'), array('empty' => '--all--') ),
'value'=>'( $data->status == 0) ? "New": ( $data->status == 1) ? "Approved" : "Declined"',
'htmlOptions' => array(
'style' => 'width: 40px; text-align: center;',
),
),
...
array(
'class'=>'CButtonColumn',
),
),
));
// CGridView
In order to save if/else in the 'value' section, you can implement a method in your model that returns the string associated to the integer.
It works great, just with the default Yii admin.php view, which you can edit as much as you need.
Update
Added support for empty status, does not filter query results
Thanks #Alex for your help but i am successful to make filterdropdown for grid , code is following but will you please tell me that i want that grid show only values where status=New , how i can do when page load grid show values where status is New
but first i paste the working code of dropdown filter for grid
Here is my admin.php file
<?php
$this->breadcrumbs = array(
'Testimonials' => array('index'),
'Manage',
);
$this->menu = array(
array('label' => 'List Testimonial', 'url' => array('index')),
array('label' => 'Create Testimonial', 'url' => array('create')),
);
?>
<h1>Manage Testimonials</h1>
<!-----------drop down form------------->
<?php
Yii::app()->clientScript->registerScript('dropdownfilter', "
$('.dropdown-form form #staticid').change(function(){
$.fn.yiiGridView.update('testimonial-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<div class="dropdown-form">
<?php
$this->renderPartial('_dropdownfilter', array(
'model' => $model,
));
?>
</div><!-- search-form -->
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'testimonial-grid',
'dataProvider' => $model->search(),
// 'filter' => $model,
'columns' => array(
'id',
'created_by',
'test_name',
'test_email',
'comments',
'created_at',
'status',
array(
'class' => 'CButtonColumn',
),
),
));
?>
Here is my render partial form where i place the static drop dow
<div class="wide form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
));
?>
<div class="row">
<?php
echo CHtml::dropDownList('staticid', '', array('0' => 'New', '1' => 'Approved', '2' => 'Declined'), array(
// 'onChange' => 'this.form.submit()',
'ajax' => array(
'type' => 'POST', //request type
)));
?>
</div>
<?php $this->endWidget(); ?>
And Here is code of my adminaction in controller
public function actionAdmin() {
$model = new Testimonial('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['staticid'])) {
$getStatus = $_GET['staticid'];
if ($getStatus == 0)
$status = 'New';
if ($getStatus == 1)
$status = 'Approved';
if ($getStatus == 2)
$status = 'Declined';
$model->status = $status;
}
if (isset($_GET['Testimonial']))
$model->attributes = $_GET['Testimonial'];
$this->render('admin', array(
'model' => $model,
));
}
Now i want that when i actionadmin triggered first time it show status=New values

CakePHP doesn't show uploaded picture

i'm truly getting crazy!
I made a gallery with Meiouploader and PHPThumb. All is working very nice.
My uploaded images saved in folder img/uploads/images and in my database too.
But in the field for showing the images I only see the alt-text. Not the images.
But when In check the HTML-Code, I see the correct path to my images. But I don't see it.
What wrong???
Please help!
OK, here is all my code:
I think the paths are correct, because in source code in my browser i can see the image - Tag. Here is my code for Image-Model:
class Image extends AppModel {
var $name = 'Image';
var $validate = array(
'gallery_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
//'img_file' => array(
//'notempty' => array(
//'rule' => array('notempty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
//),
//),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'Gallery' => array(
'className' => 'Gallery',
'foreignKey' => 'gallery_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $actsAs = array(
'MeioUpload' => array(
'img_file' => array(
'dir' => 'img{DS}uploads{DS}images',
'create_directory' => false,
'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/png'),
'allowed_ext' => array('.jpg', '.jpeg', '.png'),
'zoomCrop' => true,
'thumbnails' => true ,
'thumbnailQuality' => 75,
'thumbnailDir' => 'thumb',
'removeOriginal' => true,
'thumbsizes' => array(
'normal' => array('width' => 400, 'height' => 300),
),
'default' => 'default.jpg'
)
)
);
}
Here is my code for the Images-Controller:
class ImagesController extends AppController {
var $name = 'Images';
function index() {
$this->Image->recursive = 0;
$this->set('images', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid image', true));
$this->redirect(array('action' => 'index'));
}
$this->set('image', $this->Image->read(null, $id));
}
function add() {
if (!empty($this->data)) {
$this->Image->create();
if ($this->Image->save($this->data)) {
$this->Session->setFlash(__('The image has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The image could not be saved. Please, try again.', true));
}
}
$galleries = $this->Image->Gallery->find('list');
$this->set(compact('galleries'));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid image', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Image->save($this->data)) {
$this->Session->setFlash(__('The image has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The image could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Image->read(null, $id);
}
$galleries = $this->Image->Gallery->find('list');
$this->set(compact('galleries'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for image', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Image->delete($id)) {
$this->Session->setFlash(__('Image deleted', true));
$this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('Image was not deleted', true));
$this->redirect(array('action' => 'index'));
}
}
Here is my code for index.ctp - View:
<div class="images index">
<h2><?php __('Images');?></h2>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $this->Paginator->sort('id');?></th>
<th><?php echo $this->Paginator->sort('gallery_id');?></th>
<th><?php echo $this->Paginator->sort('name');?></th>
<th><?php echo $this->Paginator->sort('img_file');?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($images as $image):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $image['Image']['id']; ?> </td>
<td>
<?php echo $this->Html->link($image['Gallery']['name'], array('controller' => 'galleries', 'action' => 'view', $image['Gallery']['id'])); ?>
</td>
<td><?php echo $image['Image']['name']; ?> </td>
<!--<td><?php echo $image['Image']['img_file']; ?> </td>-->
<td><?php echo $html->image('uploads' . DS . 'images' . DS . $image['Image']['img_file'], array('alt' => 'Gallery Image', 'width' => '400')); ?></td>
<td class="actions">
<?php echo $this->Html->link(__('View', true), array('action' => 'view', $image['Image']['id'])); ?>
<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $image['Image']['id'])); ?>
<?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $image['Image']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $image['Image']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?>
</p>
<div class="paging">
<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
<?php echo $this->Paginator->numbers();?>
<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
</div>
</div>
<div class="actions">
<h3><?php __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('New Image', true), array('action' => 'add')); ?></li>
<li><?php echo $this->Html->link(__('List Galleries', true), array('controller' => 'galleries', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Gallery', true), array('controller' => 'galleries', 'action' => 'add')); ?> </li>
</ul>
</div>
And here is my code for the add.ctp - View:
<div class="images form">
<?php // echo $this->Form->create('Image');?>
<?php echo $form->create('Image',array('type' => 'file')); ?>
<fieldset>
<legend><?php __('Add Image'); ?></legend>
<?php
echo $this->Form->input('gallery_id');
echo $this->Form->input('name');
//echo $this->Form->input('img_file');
echo $form->input('img_file', array('type' => 'file'));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
<div class="actions">
<h3><?php __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List Images', true), array('action' => 'index'));?></li>
<li><?php echo $this->Html->link(__('List Galleries', true), array('controller' => 'galleries', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Gallery', true), array('controller' => 'galleries', 'action' => 'add')); ?> </li>
</ul>
</div>
I did all like in the tutorial of Jason Whydro, but it doesn't work well. It don't show me the pictures in this field, only the alt-text within and the width.
When I click on link to one of these images in my source code in my browser, then he says me: There is no object. The URL coudn't found on server!!
I hope it's enough for you to see whats going wrong. I don't see it. What did you mean with User Permission? How can I fix it, if this is the problem. I work with windows 8.
Greetings...
If your path is correctly it means that when you put this on your url bar at your browser , it shoud appears.
When it doesn't , could be a permission issue. Try to check your files permission to your http user.

Error on passing data from controller to view of Codeigniter

I am facing a wired problem for more than 2 hours. I couldn't figured it out. I am trying to pass the variable "errors" from model to view but when I try to load the page it shows error saying "undefined variable: errors". I am trying to build a "register" page for registering new users.
Here is my controller for register
function register(){
if($_POST){
$config = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => 'trim|required|min_length[3]|is_unique[users.username]'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required|min_length[5]'
),
array(
'field' => 'password2',
'label' => 'Password Confirm',
'rules' => 'trim|required|min_length[5]|matches[password]'
),
array(
'field' => 'user_type',
'label' => 'User Type',
'rules' => 'required'
),
array(
'field' => 'email',
'label' => 'Email',
'rules' => 'trim|required|is_unique[users.email]|valid_email'
)
);
$this->load->library('form_validation');
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){
$data['errors'] = validation_errors();
}else{
$data_array = array(
'username' => $_POST['username'],
'password' => sha1($_POST['password']),
'email' => $_POST['email'],
'user_type' => $_POST['user_type']
);
$this->load->model('user');
$userid = $this->user->create_user($data_array);
$this->session->set_userdata('userID', $userid);
$this->session->set_userdata('user_type',$_POST['user_type']);
redirect(base_url().'index.php/posts');
}
}
$this->load->helper('form');
$this->load->view('header');
$this->load->view('register_user');
$this->load->view('footer');
}
In above when there is a error in validation I set the error in $data['errors'] array.
The view is given below
<h2>Register User</h2>
<?php if($errors): ?>
<div style="background:red;color:white;">
<?php echo $errors; ?>
</div>
<?php endif; ?>
But when I open the register page on browser, it shows the error saying "Undefined variable: errors". Can anyone tell me where I have done wrong?
You are not passing any data to your views. You can use the 2nd parameter to pass data to your views so rather than doing
$this->load->view('header');
$this->load->view('register_user');
$this->load->view('footer');
You want to do
$aData['errors']
$this->load->view('header', $aData);
$this->load->view('register_user', $aData);
$this->load->view('footer', $aData);
Then when you are in your view you can do
<h2>Register User</h2>
<?php if($errors): ?>
<div style="background:red;color:white;">
<?php echo $errors; ?>
</div>
<?php endif; ?>

Recaptcha won't post in CodeIgniter project

I’ve a problem with implementing recaptcha in a CodeIgniter application.
The problem is that the recapctha_challenge_field and recaptcha_response_field do not get posted, however, the recapctcha (and those fields) is visible on the page (within the form).
The the recapctha_challenge_field and recaptcha_response_field are appearing in the HTML of the page, but not in the header when I post the form.
I’ve downloaded de recaptcha library and added it as an helper in CI.
Within the form in my view I echo the recaptcha_get_html($publickey) (with the public key set).
In my controller, I load the recaptchalib_helper and add set a form validation rule for the recapctha_challenge_field.
This is my view:
<h1>Register</h1>
<fieldset>
<legend>Personal information</legend>
<?php
echo form_open('login/create_user');
echo form_label('First name:', 'first_name');
echo form_input(
array(
'name' => 'first_name',
'id' => 'first_name',
'value' => set_value('first_name')
)
);
echo form_label('Last name:', 'last_name');
echo form_input(
array(
'name' => 'last_name',
'id' => 'last_name',
'value' => set_value('last_name')
)
);
echo form_label('Birth date:', 'birth_date');
echo form_input(
array(
'name' => 'birth_date',
'id' => 'birth_date',
'value' => set_value('birth_date')
)
);
echo form_label('E-mail:', 'email');
echo form_input(
array(
'name' => 'email',
'id' => 'email',
'value' => set_value('email')
)
);
?>
</fieldset>
<fieldset>
<legend>Login information</legend>
<?php
echo form_label('Username:', 'username');
echo form_input(
array(
'name' => 'username',
'id' => 'username',
'value' => set_value('username')
)
);
echo form_label('Password:', 'password1');
echo form_password(
array(
'name' => 'password1',
'id' => 'password1',
'value' => set_value('password1')
)
);
echo form_label('Confirm password:', 'password2');
echo form_password(
array(
'name' => 'password2',
'id' => 'password2',
'value' => set_value('password2')
)
);
$publickey = "mypublickey"; // here I entered my public key
echo recaptcha_get_html($publickey);
echo form_label(nbs(1), 'submit');
echo form_submit(
array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Registreren'
)
);
echo form_close();
?>
<?php echo validation_errors('<p class="error">'); ?>
</fieldset>
</div>
and this is a part of my controller:
function create_user() {
print_r($_POST);//for debugging
$this->load->library('form_validation');
$this->load->model('user');
$this->form_validation->set_rules('recaptcha_challenge_field', 'Captcha', 'callback_validate_captcha');
$this->form_validation->set_rules('first_name', 'First name', 'trim|xss_clean|required');
$this->form_validation->set_rules('last_name', 'Last name', 'trim|xss_clean|required');
$this->form_validation->set_rules('email', 'E-mail', 'trim|xss_clean|valid_email|callback_is_email_available|required');
$this->form_validation->set_rules('username', 'Username', 'trim|xss_clean|min_length[5]|callback_is_username_available|required');
$this->form_validation->set_rules('password1', 'Password', 'trim|xss_clean|min_length[8]|max_length[32]|required');
$this->form_validation->set_rules('password2', 'Confirm password', 'trim|xss_clean|matches[password1]|required');
if ($this->form_validation->run() == FALSE) {
$this->signup();
} else {
if ($this->user->create_user($this->input->post('username'),$this->input->post('password1'),$this->input->post('email'),$this->input->post('first_name'),$this->input->post('last_name'),$this->input->post('birth_date'))) {
$data['main_content'] = 'login/signup_successful';
$this->load->view('includes/template', $data);
} else {
$this->load->view('login/signup_form');
}
}
}
public function validate_captcha($recaptcha_challenge_field) {
$this->load->helper('recaptchalib');
$privatekey = "myprivatekey";//this is et to my private key
$resp = recaptcha_check_answer ($privatekey,
$this->input->ip_address(),
$this->input->post("recaptcha_challenge_field"),
$this->input->post("recaptcha_response_field"));
if (!$resp->is_valid) {
$this->form_validation->set_message('validate_captcha', 'Invalid Capctha code entered.');
return FALSE;
} else {
return TRUE;
}
}
The capctha fields are not set in the HTTP headers:
Form data:
csrf_test_name:8cc3f2391784867df2d46f193a65a317
first_name:Myfirstname
last_name:Mylastname
birth_date:10-12-2012
email:myemail#adres.com
username:username
password1:password
password2:password
submit:Register
What am I doing wrong?
Your sincerely,
Alwin
Does the form tag not begin within a table, tbody or tr?

Resources