Images are not showing in the login view after logging out - codeigniter

This is the actual login page
The 2nd pic is when the user logs out or has validation errors
And this is my current code
<?php
echo form_open('login/validate_credentials');
echo '<img src="img/too.png" style="height: 30px">'.form_input( 'username', '');
echo '<img src="img/pwd.png" style="height: 30px">'.form_password('password', '');
echo '<br>';
echo form_submit('submit', 'Login');
echo form_close();
?>

You should use HTml Helper to display images
echo form_open('login/validate_credentials');
echo img(array('src' => 'img/too.png', 'height' => '30px')) . form_input( 'username', '');
echo img(array('src' => 'img/pwd.png', 'height' => '30px')) .form_password('password', '');
echo '<br>';
echo form_submit('submit', 'Login');
echo form_close();

try this...
<form method="post" action="<?php echo base_url();?>login/validate_credentials">
<img src="<?php echo base_url('imagepath');" style="height: 30px">
<input type="text" name="username" id="username" value="">
<img src="img/pwd.png" style="height: 30px">
<input type="password" name="password" id="password" value="">
<input type="submit" name="Login">

Related

What is the cause of this wrong image upload error message in my Codeigniter 3 application?

I am working on a basic blog application with Codeigniter 3.1.8 and Bootstrap 4.
There is, among others an "Edit account information" form, which has an image upload field. In the controller, the update() method contains the logic for the image upload action:
public function update() {
// Only logged in users can edit user profiles
if (!$this->session->userdata('is_logged_in')) {
redirect('login');
}
$id = $this->input->post('id');
$data = $this->Static_model->get_static_data();
$data['pages'] = $this->Pages_model->get_pages();
$data['categories'] = $this->Categories_model->get_categories();
$data['author'] = $this->Usermodel->editAuthor($id);
$this->form_validation->set_rules('first_name', 'First name', 'required');
$this->form_validation->set_rules('last_name', 'Last name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_error_delimiters('<p class="error-message">', '</p>');
// Upload avatar
$config['upload_path'] = './assets/img/avatars';
$config['allowed_types'] = 'jpg|jpeg|png';
$config['max_size'] = '100';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile')) {
$uerrors = array('uerrors' => $this->upload->display_errors());
$data['uerrors'] = $uerrors;
}
if(!$this->form_validation->run() || !empty($uerrors))
{
print_r($data['uerrors']);
$this->load->view('partials/header', $data);
$this->load->view('dashboard/edit-author');
$this->load->view('partials/footer');
} else
{
$this->Usermodel->update_user($id);
$this->session->set_flashdata('user_updated', 'Your account details have been updated');
redirect(base_url('/dashboard/manage-authors'));
}
}
The (surprising) problem I have is that, even though I am uploading an image, print_r($data['uerrors']); returns You did not select a file to upload. in the browser.
In the view, the same error is returned:
<?php echo form_open(base_url('dashboard/users/update')); ?>
<input type="hidden" name="id" id="uid" value="<?php echo $author->id; ?>">
<div class="form-group <?php if(form_error('first_name')) echo 'has-error';?>">
<input type="text" name="first_name" id="first_name" class="form-control" value="<?php echo set_value('first_name', $author->first_name); ?>" placeholder="First name">
<?php if(form_error('first_name')) echo form_error('first_name'); ?>
</div>
<div class="form-group <?php if(form_error('last_name')) echo 'has-error';?>">
<input type="text" name="last_name" id="last_name" class="form-control" value="<?php echo set_value('last_name', $author->last_name); ?>" placeholder="Last name">
<?php if(form_error('last_name')) echo form_error('last_name'); ?>
</div>
<div class="form-group <?php if(form_error('email')) echo 'has-error';?>">
<input type="text" name="email" id="email" class="form-control" value="<?php echo set_value('email', $author->email); ?>" placeholder="Email">
<?php if(form_error('email')) echo form_error('email'); ?>
</div>
<div class="form-group <?php if(form_error('bio')) echo 'has-error';?>">
<textarea name="bio" id="bio" cols="30" rows="5" class="form-control" placeholder="Add a short bio"><?php echo set_value('bio', $author->bio); ?></textarea>
<?php if(form_error('bio')) echo form_error('bio'); ?>
</div>
<input type="hidden" name="avatar" id="avatar" value="<?php echo $author->avatar; ?>">
<label for="avatar">Upload avatar</label>
<div class="form-group">
<input type="file" name="userfile" id="uavatar" size="20">
<p><?php print_r($uerrors); ?></p>
</div>
<div class="form-group">
<div class="w-50 pull-left pr-1">
<input type="submit" value="Update" class="btn btn-block btn-md btn-success">
</div>
<div class="w-50 pull-right pl-1">
Cancel
</div>
</div>
<?php echo form_close(); ?>
The error message I was expecting, considering that the image I was trying to upload is larger then the specified limit (100KB) is: The file you are attempting to upload is larger than the permitted size.
What am I doing wrong?
Try this
<?php echo form_open_multipart(base_url('dashboard/users/update')); ?>
<div class="form-group">
<input type="file" name="userfile" id="userfile" size="20">
<p><?php print_r($uerrors); ?></p>
</div>
Try to change your form opening, from :
<?php echo form_open(base_url('dashboard/users/update')); ?>
to
<?php echo form_open_multipart(base_url('dashboard/users/update')); ?>
To change the form encoding type from text/plain to multipart/form-data to support image data upload. Here is the difference between each encoding type.

Generating admission number using id in MYSQL. I want code from CodeIgniter

In my project, I have a student id no. It should auto increment. I want to auto-generate an admission number. How do I do it?
This is my controller
$insert_id = $this->student_model->add($data);
$data_new = array(
'student_id' => $insert_id,
'class_id' => $class_id,
'section_id' => $section_id,
This is my model
public function add($data) {
if (isset($data['id'])) {
$this->db->where('id', $data['id']);
$this->db->update('students', $data);
} else {
$this->db->insert('students', $data);
return $this->db->insert_id();
}
}
Here is my view
<form id="form1" action="<?php echo site_url('student/create') ?>" id="employeeform" name="employeeform" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<div class="box-body">
<div class="tshadow mb25 bozero">
<h4 class="pagetitleh2"><?php echo $this->lang->line('student'); ?> <?php echo $this->lang->line('admission'); ?> </h4>
<div class="around10">
<?php if ($this->session->flashdata('msg')) { ?>
<?php echo $this->session->flashdata('msg') ?>
<?php } ?>
<?php echo $this->customlib->getCSRF(); ?>
<input type="hidden" name="sibling_name" value="<?php echo set_value('sibling_name'); ?>" id="sibling_name_next">
<input type="hidden" name="sibling_id" value="<?php echo set_value('sibling_id',0); ?>" id="sibling_id">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="exampleInputEmail1"><?php echo $this->lang->line('admission_no'); ?></label> <small class="req"> *</small>
<input autofocus="" id="admission_no" name="admission_no" placeholder="" type="text" class="form-control" value="<?php echo set_value('admission_no', date($this->customlib->getSchoolDateFormat())); ?>" name="admission_no" class="form-control">
<span class="text-danger"><?php echo form_error('admission_no'); ?></span>
</div>
Here admission number put manually, but I want it auto-created. I don't know how to do. I'm new with CodeIgniter.
My database
My form view
if you want to add unique admission you must chick the admission or use this query
$this->db->order_by('admission_no','DESC');
$this->db->get('students',1)->row()->admission_no + 1;
Put the bellow code in your view in your admission input which id of it is id="admission_no" romove the input and copy paste the code. this get the lastest admission no and then add 1 to the admission no also you can remove this value and add manually another value. that must be unique
<?php
$this->db->order_by('admission_no','DESC');
$auto-add = $this->db->get('students',1)->row()->admission_no + 1;
?>
<input autofocus="" id="admission_no" name="admission_no" placeholder="" type="text" class="form-control" value="<?php echo $auto-add; ?>" class="form-control">

Payumoney Error while integrating codeigniter

I am working on codeigniter and integrating the payumoney payment gateway. Here I have a registration form and there are various fields in the form Now what I am doing I want to add payumoney payment gateway but the problem is this when I add write the fname or amount from myself the it works fine but while I use $this->input->post('first_name') It shows error like follows
click to view the image (Here is the error in the image)
Here is the data variables
the values for data array
My code is follows :
function checkout() {
$this->load->config('payu');
$MERCHANT_KEY = $this->config->item('MERCHANT_KEY');
$SALT = $this->config->item('SALT');
$PAYU_BASE_URL = $this->config->item('PAYU_BASE_URL');
$action = '';
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$udf1 = '';
$udf2 = '';
$udf3 = '';
$udf4 = '';
$udf5 = '';
$amount = $this->input->post('corporate_plan_rate');
$productinfo = 'test';
$fname = $this->input->post('user_name');
$email = $this->input->post('user_email');
$data = array(
'mkey' => $MERCHANT_KEY,
'tid' => $txnid,
'MERCHANT_KEY'=>$MERCHANT_KEY,
'txnid'=>$txnid,
'SALT'=>$SALT,
// 'hash' => $hash,
'amount' => $amount,
'pinfo' => $productinfo,
'name' => $fname,
'productinfo'=>$productinfo,
'mailid' => $email,
'phoneno' => '9646403748',
'udf1' => $udf1,
'udf2' => $udf2,
'udf3' => $udf3,
'udf4' => $udf4,
'udf5' => $udf5,
);
$this->load->view('payu/checkout.php', $data);
}
and here is my view page:
<html>
<head>
<!--<script src="//code.jquery.com/jquery.min.js"></script>-->
<script>
// $(function () {
// setTimeout(function () {
// $('form').submit();
// }, 2000)
// });
</script>
</head>
<body>
<?php
$hashstring = $MERCHANT_KEY . '|' . $txnid . '|' . $amount . '|' . $productinfo . '|' . $name . '|' . $mailid . '|' . $udf1 . '|' . $udf2 . '|' . $udf3 . '|' . $udf4 . '|' . $udf5 . '||||||' . $SALT;
$hash = strtolower(hash('sha512', $hashstring));
?>
<h2>PayU Form</h2>
<br/>
<form method="post" name="payuForm" action="https://test.payu.in/_payment">
<input name="key" type="hidden" value="<?php echo $mkey ?>" />
<input name="txnid" type="hidden" value="<?php echo $tid ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input name="amount" type="hidden" value="<?php echo $amount; ?>" />
<input name="productinfo" type="hidden" value="<?php echo $pinfo; ?>">
<input type="hidden" name="service_provider" value="payu_paisa" size="64" />
<input name="udf1" type="hidden" value="">
<input name="udf2" type="hidden" value="">
<input name="udf3" type="hidden" value="">
<input name="udf4" type="hidden" value="">
<input name="udf5" type="hidden" value="">
<input name="firstname" id="firstname" type="hidden" value="<?php echo $name; ?>"/>
<input name="email" id="email" type="hidden" value='<?php echo $mailid; ?>'>
<input name="phone" type="hidden" value="<?php echo $phoneno; ?>">
<input name="surl" type="hidden" value="<?php echo base_url('payu/success'); ?>" size="64" />
<input name="furl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" size="64" />
<input name="curl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" />
<input type="submit" name="submit_form" value="Click Here for Payment" class="btn btn-info btn-block" >
</form>
</body>
</html>
Please help me find out the problem and resolve it out.. Thanx
Please completely replace your controller function with below codes
function checkout()
{
$MERCHANT_KEY = "enter your test merchant key here";
$SALT = "enter your test salt here";
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$udf1 = '';
$udf2 = '';
$udf3 = '';
$udf4 = '';
$udf5 = '';
$amount = $this->input->post('corporate_plan_rate');
$productinfo = 'test_payment';
$fname = $this->input->post('user_name');
$email = $this->input->post('user_email');
$hashstring = $MERCHANT_KEY . '|' . $txnid . '|' . $amount . '|' . $productinfo . '|'. $fname . '|' . $email .'|'.$udf1.'|' .$udf2.'|' .$udf3.'|'.$udf4.'|'.$udf5.'||||||'. $SALT;
$hash = strtolower(hash('sha512', $hashstring));
$data = array(
'mkey' => $MERCHANT_KEY,
'tid' => $txnid,
'hash' => $hash,
'amount' => $amount,
'pinfo' => $productinfo,
'name' => $fname,
'productinfo'=>$productinfo,
'mailid' => $email,
'phoneno' => '9646403748',
);
$this->load->view('payu/checkout', $data);
}
Now completely replace your checkout view file with following codes
<html>
<head>
</head>
<body>
<h2>PayU Form</h2>
<br/>
<form method="post" name="payuForm" action="https://test.payu.in/_payment">
<input name="key" type="hidden" value="<?php echo $mkey ?>" />
<input name="txnid" type="hidden" value="<?php echo $tid ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input name="amount" type="hidden" value="<?php echo $amount; ?>" />
<input name="productinfo" type="hidden" value="<?php echo $pinfo; ?>">
<input type="hidden" name="service_provider" value="payu_paisa" size="64" />
<input name="udf1" type="hidden" value="">
<input name="udf2" type="hidden" value="">
<input name="udf3" type="hidden" value="">
<input name="udf4" type="hidden" value="">
<input name="udf5" type="hidden" value="">
<input name="firstname" id="firstname" type="hidden" value="<?php echo $name; ?>"/>
<input name="email" id="email" type="hidden" value='<?php echo $mailid; ?>'>
<input name="phone" type="hidden" value="<?php echo $phoneno; ?>">
<input name="surl" type="hidden" value="<?php echo base_url('payu/success'); ?>" size="64" />
<input name="furl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" size="64" />
<input name="curl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" />
<input type="submit" name="submit_form" value="Click Here for Payment" class="btn btn-info btn-block" >
</form>
</body>
</html>
Please try above code without adding any of your own codes for testing and if the same error occurs comment below.

Wordpress/woocommerce redirect after registration

I have a custom registration page on my Woocommerce site created by a developer who has gone awol.
Once you have registered on the website it redirects you to:
http://www.punjaban.co.uk/wp-admin/admin-ajax.php?action=load_lightbox&lightboxTemplate=register
which is wrong and only displays the my-account page but with no formatting.
I tried adding:
function punjaban_registration_redirect() {
return home_url;
}
add_filter( 'registration_redirect', 'punjaban_registration_redirect' );
but that has not worked. Can anyone point me in the right direction please.
The custom register.php code is:
<?php global $myaccount_page_url; ?>
<h1><?php _e( 'Create an account', 'woocommerce' ); ?></h1>
<form method="post" class="register account-form" action="<?php echo $myaccount_page_url; ?>?action=register">
<?php do_action( 'woocommerce_register_form_start' ); ?>
<div class="row">
<div class="column xsmall-12 small-6">
<input type="text" name="billing_first_name" id="reg_billing_first_name" placeholder="<?php esc_attr_e( 'FIRST NAME', 'punjaban' ); ?>" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</div>
<div class="column xsmall-12 small-6">
<input type="text" name="billing_last_name" id="reg_billing_last_name" placeholder="<?php esc_attr_e( 'LAST NAME', 'punjaban' ); ?>" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
</div>
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) : ?>
<div class="column xsmall-12">
<label for="reg_username"><?php _e( 'Username', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="reg_username" placeholder="<?php esc_attr_e( 'USERNAME', 'punjaban' ); ?>" value="<?php if ( ! empty( $_POST['username'] ) ) echo esc_attr( $_POST['username'] ); ?>" />
</div>
<?php endif; ?>
<div class="column xsmall-12">
<label for="reg_email"><?php _e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" placeholder="<?php esc_attr_e( 'EMAIL ADDRESS', 'punjaban' ); ?>" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?>" />
</div>
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) : ?>
<div class="column xsmall-12">
<input type="password" name="password" id="reg_password" placeholder="<?php esc_attr_e( 'PASSWORD', 'punjaban' ); ?>" />
</div>
<?php endif; ?>
<!-- Spam Trap -->
<div style="left: -999em; position: absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woocommerce' ); ?></label>
<input type="text" name="email_2" id="trap" tabindex="-1" /></div>
<div class="column xsmall-12">
<input type="password" name="password2" id="reg_password2" placeholder="<?php esc_attr_e( 'CONFIRM PASSWORD', 'punjaban' ); ?>" />
</div>
<div class="column xsmall-12">
<div class="custom-checkbox">
<input name="newsletter" type="checkbox" id="newsletter" value="1" checked="checked" />
<label for="newsletter"><span class="icon"></span> <?php _e('Keep me posted with new recipes and news','punjaban'); ?></label>
</div>
</div>
<?php do_action( 'woocommerce_register_form' ); ?>
<?php do_action( 'register_form' ); ?>
<div class="column xsmall-12">
<?php wp_nonce_field( 'woocommerce-register' ); ?>
<input type="submit" class="btn form-btn" name="register" value="<?php _e( 'CREATE ACCOUNT', 'punjaban' ); ?>" />
</div>
</div>
<?php do_action( 'woocommerce_register_form_end' ); ?>
</form>
<div class="login-switch">
<h2>Already have an account?</h2>
<?php _e( 'LOGIN', 'woocommerce' ); ?>
</div>
Thanks in advance.
You are probably returning wrong value.
You should return homer_url(); function.
--EDIT
Also you could try "woocommerce_registration_redirect" filter instead of "registration_redirect"

Validate with codeigniter

I dont know what am i doing wrong with the validation.
here is my Controller
function update_user() {
$this->load->library('form_validation');
$this->form_validation->set_rules('sirname', 'First Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('name', 'Last Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email');
if ($this->form_validation->run() == FALSE)
{
// fails
$this->load->view('update_view');
}
else
{
$data = array(
'surname' => $this->input->post('sirname'),
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
);
$this->Account_model->update_user(31,$data);
$this->show_user();
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Updated!</div>');
redirect('home');
}
}
here is my view
<form method="post" action="<?php echo base_url() . "account/update_user"?>" >
<div class="form-group">
<label for="name">First Name</label>
<input class="form-control" name="sirname" placeholder="Your First Name" type="text" value="<?php echo $user->surname; ?>" />
<span class="text-danger"><?php echo form_error('sirname'); ?></span>
</div>
<div class="form-group">
<label for="name">Last Name</label>
<input class="form-control" name="name" placeholder="Last Name" type="text" value="<?php echo $user->name; ?>" />
<span class="text-danger"><?php echo form_error('name'); ?></span>
</div>
<div class="form-group">
<label for="email">Email ID</label>
<input class="form-control" name="email" placeholder="Email-ID" type="text" value="<?php echo $user->email; ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
<div class="form-group">
<button name="submit" type="submit" class="btn btn-default" onclick="account.php">Update</button>
<button name="cancel" type="reset" class="btn btn-default">Cancel</button>
</div>
<?php echo form_close(); ?>
<?php endforeach; ?>
<?php echo $this->session->flashdata('msg'); ?>
i need to display the value already in the database as im doing an update info for user.. so how do i implement the set_value('name') as well.
First preference is for form_error(),
so in value for each input fields,
value="<?php form_error("surname") ? echo set_value("surname") : echo $user->surname; ?> ?>"
Which means, if form error, then echo set_value() else echo database value.
in home controller where you redirect to success load :
$this->load->library('form_validation');
it will be ok!
You can use CI's built-in set_value function, which lets you set the values of a form field. It has a second (optional) parameter, to set the default value for the field.
<? echo form_label('Last Name', 'name'); ?>
<input class="form-control" name="name" id="name" type="text" value="<? echo set_value('name', $user->name) ?>">
<? echo form_error('name', '<span class="text-danger">','</span>');?>
In the code above, when loaded for the first time, the form will show the value from the database. But when returned after failing form validation, it will show the user input.

Resources