codeigniter form_error() not showing error beside form-control - codeigniter

I am trying to show validation errors beside the form-control but form_error() is not working.
codeigniter form_error() not showing error beside form-control
The validation_errors() is working but form_error() not working beside the input control
Admin Controller
<?php
class Admin extends CI_Controller
{
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('uname','Username','required|alpha');
$this->form_validation->set_rules('pass','Password','required|max_length[12]');
$this->form_validation->set_error_delimiters("<div class='text-danger'>","</div>");
if($this->form_validation->run())
{
echo "Validation successful";
}
else
{
//echo validation_errors();
$this->load->view('Users/articleList');
}
}
}
?>
The view is
application/views/Users
<?php include('header.php'); ?>
<div class="container" style="margin-top:20px";>
<h1> Admin Form </h1>
<?php echo form_open('admin/index');?>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="Username">Username</label>
<?php echo form_input(['class'=>'form-control', 'placeholder'=>'Enter Username','name'=>'uname']);?>
</div>
</div>
<div class="col-lg-6">
<?php form_error('uname');?>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="Password">Password</label>
<?php echo form_password(['class'=>'form-control','type'=>'password',
'placeholder'=>'Enter Password', 'name'=>'pass'
]);?>
</div>
<div class="col-lg-6">
<?php form_error('pass');?>
</div>
</div>
</div>
<?php echo form_submit(['type'=>'submit', 'class'=>'btn btn-default','value'=>'Submit']); ?>
<?php echo form_reset(['type'=>'submit', 'class'=>'btn btn-default','value'=>'Reset']); ?>
</div>
<?php echo validation_errors();?>
<?php include('footer.php'); ?>

You need to echo the form_error so...
<?php form_error('pass');?>
becomes
<?php echo form_error('pass');?>
or
<?= form_error('pass');?>

Related

Changing password of the signed in user in code igniter

I am working on Code Igniter and stuck in a place where I need to change the password of a signed-in user. I need help in picking up the user id of the signed-in user and through it I want to update the password of that user.
The following are the images of controller and models created of the project respectively.
Create html link:
<i class="fa fa-circle-o"></i>Change password
Create user controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
// Load form helper library
$this->load->helper('form');
// Load form validation library
$this->load->library('form_validation');
// Load session library
$this->load->library('session');
$this->load->model('Data_model');
}
public function changePassword()
{
$web = array();
$web['title'] = 'Change password';
$web['content'] = 'web/password';
$this->form_validation->set_rules('old_password', 'Old password', 'required|callback_check_password');
$this->form_validation->set_rules('new_password', 'New password', 'required');
$this->form_validation->set_rules('confirm_password', 'Confirm password', 'required|matches[new_password]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('web_template',$web);
} else {
$id = $this->user_id;
$data = array(
'user_password' => $this->input->post('new_password'),
);
$this->Common_model->Data_model('user_login', $data, 'id', $id);
$this->session->set_flashdata('msg', 'Password changed Successfully');
redirect('user/changePassword');
}
}
function check_password($password) {
if($this->user_id)
$id = $this->user_id;
else
$id = '';
$result = $this->Data_model->check_user_password($id, $password);
if($result > 0)
$response = true;
else {
$this->form_validation->set_message('check_password', 'Old password is wrong');
$response = false;
}
return $response;
}
}
Change password html page in view:
<section class="content">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title"><?php echo $title; ?></h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i></button>
</div>
</div>
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'changePassword');
echo form_open('user/changePassword', $attributes);
?>
<div class="box-body">
<?php if (!empty($this->session->flashdata('msg'))) : ?>
<div class="alert alert-success alert-dismissable alertDiv"> <?php echo $this->session->flashdata('msg'); ?> </div>
<?php endif; ?>
<div class="row">
<div class="col-md-offset-2 col-md-8">
<div class="form-group">
<label for="inputEmail3" class="col-md-2 control-label">Old password</label>
<div class="col-md-8">
<input type="password" name="old_password" value="<?php echo (isset($form_data) ? $form_data->old_password : set_value('old_password')); ?>" class="form-control" id="old_password" placeholder="Old password">
<?php echo form_error('old_password', '<div class="error">', '</div>'); ?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-offset-2 col-md-8">
<div class="form-group">
<label for="inputEmail3" class="col-md-2 control-label">New password</label>
<div class="col-md-8">
<input type="password" name="new_password" value="<?php echo (isset($form_data) ? $form_data->new_password : set_value('new_password')); ?>" class="form-control" id="new_password" placeholder="New password" autocomplete="off">
<?php echo form_error('new_password', '<div class="error">', '</div>'); ?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-offset-2 col-md-8">
<div class="form-group">
<label for="inputEmail3" class="col-md-2 control-label">Confirm Password</label>
<div class="col-md-8">
<input type="password" name="confirm_password" value="<?php echo (isset($form_data) ? $form_data->confirm_password : set_value('confirm_password')); ?>" class="form-control" id="confirm_password" placeholder="Confirm Password" autocomplete="off">
<?php echo form_error('confirm_password', '<div class="error">', '</div>'); ?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-offset-5" style="margin-top: 10px;">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
<?php form_close(); ?>
</div>
<!-- /.box -->
</section>
Create Data_model in model add this function:
// Update data to table
public function update($table, $data, $primaryfield, $id)
{
$this->db->where($primaryfield, $id);
$q = $this->db->update($table, $data);
return $q;
}
//Check the old password:
function check_user_password($id = '', $password) {
$this->db->where('user_password', $password);
$this->db->where('id', $id);
return $this->db->get('user_login')->num_rows();
}

Magento 1.9 order comment ADD do backend info

I am trying to add a box for customers to place a comment on their order.
I've added it to my
/checkout/cart/cart.phtml
You can see I added it here
<div class="cart-collaterals">
<div class="row">
<th><?php echo $this->__('Comments') ?></th>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6">
<?php echo "Any special requirements regarding this order?"; ?>
<!-- COmments box -->
<td class="a-center">
<textarea name="cart[<?php echo $_item->getId() ?>][comments]" rows="3" cols="20"><?php echo $_item->getItemcomment() ?></textarea>
</td>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4">
<?php echo $this->getChildHtml('coupon') ?>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<?php echo $this->getChildHtml('checkout.cart.extra') ?>
<?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<div class="cart-totals">
<span id='ajax_loadertotals' style='display:none'><!--<img src='<?php //echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/>--><div class="loaderTotals">Loading...</div></span>
<div class="totals">
<?php echo $this->getChildHtml('totals'); ?>
<?php if(!$this->hasError()): ?>
<ul class="checkout-types">
<?php foreach ($this->getMethods('methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
<div id="shipping-info-link">
Delivery & Shipping Information
</div>
</div>
</div>
<?php
echo $this->getLayout()->createBlock('giftcard/checkout_cart_giftcard')->setTemplate('mt/giftcard/checkout/cart/giftcard.phtml')->toHtml();
?>
<?php echo $this->getChildHtml('crosssell') ?>
</div>
Now my problem comprises here:
How can I make it so I (the sales person) can see it on the backend when the order comes through?
I don't mind changing this to the checkout page if it makes it easier. If you could give me some help with it, I'd really appreciate. I've looked around but didn't find anything useful
Thanks
1)Add custom field/attribute in sales_flat_order table using install script, the sample is given below
$installer = $this;
$installer->startSetup();
$installer->getConnection()
->addColumn(
$installer->getTable('sales/order'), 'cutom_comment', 'VARCHAR(150) NOT NULL'
);
$installer->endSetup();
2) Add the field into the checkout page
3) You can use the event "checkout_type_onepage_save_order"
4) you can get the value using Mage::app()->getRequest()->getPost('custom_comment')
5) get the order details using $order = $observer->getEvent()->getOrder();
6) save the order
$order->setCustomComment($comment);
7) add a custom layout for admin
for that ref
8 ) get order details with $order = $this->getOrder()
9) get value by $customComment = "$order->getCustomComment();"

if click default button address should be default

One user multiple shipping address how to make it as default,if click the make as default button,that address should be default and remaining all address shown the make as default button in a particular address box,except default address box.
view page
<?php foreach ($buyer_Address as $row) { ?>
<div class="col-md-4">
<div class="panel panel-default add_min_height">
<div class="panel-heading">Default:</div>
<input type="hidden" name="de" id="de" value="<?php echo $row->b_id; ?>">
<div class="panel-body">
<address><?php echo $row->b_fullname; ?><br>
<?php echo $row->b_street_address; ?>,<?php echo $row->b_locality ?>,<br>
<?php echo $row->b_landmark; ?>,
<?php echo $row->b_city; ?>, <?php echo $row->b_state; ?>,<?php echo $row->b_pincode; ?>
India
Phone number: <?php echo $row->b_mobile_number; ?></address>
</div>
<div class="panel-footer">
<a href="<?php echo base_url(); ?>index.php/welcome/buyereditaddress?id=<?php echo $row->b_id; ?>" >Edit</a>
<i class="fa fa-ellipsis-v"></i>
Delete
<i class="fa fa-ellipsis-v"></i>
<?php if ($row->status == '0') { ?>
<button type="submit" style="color:#337ab7;background: none !important;border: none;" name="default" id="default">Make as deafault</button>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
controller
public function defaultAddress() {
$id = $this->input->post('de');
$this->BuyerProfile_Model->defaultAddress($id);
redirect('welcome/buyeraddresses');
}
model
function defaultAddress($id) {
$this->db->trans_start();
$this->db->query("UPDATE buyer_order_address SET status = '0' WHERE b_id = '$id'");
$this->db->query("UPDATE buyer_order_address SET status = '1' WHERE b_id = '$id'");
$this->db->trans_complete();
}

why does $this->form_validation->run() always return false in codeigniter 3.0.0 with php7.1 on ubuntu 16.04?

This is part of the code, it made me cannot login, i don't know where is the problem. When i tried to log in, it has no effect. Sorry for my bad english.
public function login()
{
if ($this->identity->is_admin())
redirect('admin/dashboard');
if ($this->identity->is_contestant())
redirect('contestant/dashboard');
$this->form_validation->set_rules('form[username]', $this->lang->line('username'), 'trim|required|max_length[50]');
$this->form_validation->set_rules('form[password]', $this->lang->line('password'), 'trim|required|max_length[50]');
if ($this->form_validation->run())
{
$credentials = $this->input->post('form');
if ($this->identity->login($credentials))
{
if ($this->identity->is_admin())
redirect('admin/dashboard');
else
redirect('contestant/dashboard');
}
else
{
$this->session->set_flashdata('error', $this->lang->line('wrong_credentials'));
redirect('site/login');
}
}
else
{
$this->ui['header']['title'] = $this->lang->line('login');
$this->ui['header']['page'] = 'login';
$this->load->view('site/header', $this->ui['header']);
$this->load->view('site/login', $this->ui['content']);
$this->load->view('footer', $this->ui['footer']);
}
}
Here are the login site source code.
<div class="container">
<div class="row">
<div class="col-md-12">
<ul class="breadcrumb">
<li>
<i class="glyphicon glyphicon-off"></i> <?php echo $this->lang->line('please_login'); ?>
</li>
</ul>
</div>
</div>
<?php if ($this->session->flashdata('error')) : ?>
<div class="row">
<div class="col-md-5">
<div class="alert alert-danger">
<?php echo $this->session->flashdata('error'); ?>
</div>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col-md-12">
<form class="form-horizontal" action="" method="post">
<div class="form-group<?php echo form_error('form[username]') ? ' has-error' : ''; ?>">
<label class="col-sm-1 control-label"><?php echo $this->lang->line('username'); ?>:</label>
<div class="col-sm-4">
<input name="form[username]" type="text" maxlength="30" class="form-control" value="<?php echo set_value('form[username]'); ?>" autofocus="on"/>
<span class="help-block"><?php echo form_error('form[username]'); ?></span>
</div>
</div>
<div class="form-group<?php echo form_error('form[password]') ? ' has-error' : ''; ?>">
<label class="col-sm-1 control-label"><?php echo $this->lang->line('password'); ?>:</label>
<div class="col-sm-4">
<input name="form[password]" type="password" maxlength="30" class="form-control"/>
<span class="help-block"><?php echo form_error('form[password]'); ?></span>
</div>
</div>
<div class="form-actions col-sm-offset-1">
<button type="submit" class="btn btn-danger col-sm-3"><i class="glyphicon glyphicon-user"></i> <?php echo $this->lang->line('login'); ?></button>
</div>
</form>
</div>
</div>
is it true that php7.1 is not supported by CI 3.0.0 so the error happened by this?

model->validate displays errors for text field which has value in yii

I have an application where user has to fill a lengthy form, so I split the form into three and created steps - Step 1, Step 2 etc. So it has to be convenient for users. Now I face a problem, after filling out the details, a text field shows an error. When using model->get Errors() the error is 'address cannot be blank'. When I use $_POST the arrays displays value for the field address. I started yii framework last week and I do not know where I have gone wrong. Any help appreciated.
The view code i use forloop to reduce my code -
<fieldset>
<?php if(!Yii::app()->user->hasFlash('success')):
Yii::app()->user->setFlash('warning','All Fields are mandatory!');
endif; ?>
<?php echo CHtml::errorSummary($model, null, null, array(
'class' => 'alert alert-danger col-lg-offset-2',
)); ?>
<?php $rrr = -1;
foreach($model->attributeLabels() as $a){ $rrr++;
if($rrr<27 && $rrr>=12){
?>
<div class="form-group">
<?php echo CHtml::activeLabel($model, $a, array('class' => 'col-lg-3 control-label')); ?>
<div class="col-lg-7">
<?php echo CHtml::activeTextField($model,array_keys($model->attributeLabels())[$rrr],array('value'=>'a','size'=>255,'maxlength'=>255,'class'=>'form-control formtype1')); ?>
</div>
</div>
<?php
}}
?>
<?php $rrr = -1;
foreach($model2->attributeLabels() as $a){ $rrr++;
if($rrr>1 && $rrr<6){
?>
<div class="form-group">
<?php echo CHtml::activeLabel($model2, $a, array('class' => 'col-lg-3 control-label')); ?>
<div class="col-lg-7">
<?php echo CHtml::activeTextField($model2,array_keys($model2->attributeLabels())[$rrr],array('value'=>'a','size'=>255,'maxlength'=>255,'class'=>'form-control formtype1')); ?>
</div>
</div>
<?php
}}
?>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-sm btn-primary" type="submit"><?php echo Yii::t("user", "Submit") ?></button>
</div>
</div>
</fieldset>
</form>

Resources