I have installed xampp with upgraded php 7.4.10 version because of the higher version installed captcha is not showing image showing blank (code is blank in white background).
enter image description here
Please find below screenshot of code
Javascript of html file login.phtml
if(document.frm_login.password.value!="")
{
var hash = CryptoJS.HmacSHA256(document.frm_login.password.value, "");
$('#passwords').text('');
document.frm_login.password.value=mixUpValues(hash.toString(),
document.frm_login.keyy.value,document.frm_login.keyy1.value);
}
if(document.frm_login.vercode.value==""||document.frm_login.vercode.value==null)
{
$('#captcha-code').text('Please enter code!');
$('#vercode').focus();
return false;
}
if(document.frm_login.vercode.value!=""||document.frm_login.vercode.value!=null)
{
$('#captcha-code').text('');
}
Html code of login.phtml
<div class="form-group captcha">
<?php echo $this->form->vercode; ?>
<p><span><img src="<?php echo $this->baseUrl('cool_capcha/captcha.php'); ?>"
id="captcha" /></span>
<a onclick="document.getElementById('captcha').src='<?php echo $this-
>baseUrl('cool_capcha/captcha.php'); ?>?'+Math.random();
document.getElementById('vercode').focus();"id="change-image" class="menu4
refresh" style="cursor:pointer">
<img src="./images/refress.png" class ="refresh" id="refresh" /></a></p>
<div class="clearfix"></div><span class="require" id="captcha-code">
</span>
</div>
Forms Auth.php
$this->addElement('text', 'vercode', array(
//'label' => 'Please enter the 5 letters displayed below:',
'required' => true,
'class' => 'form-control captchain',
'placeholder' => 'Captcha',
'autocomplete' => 'off',
'decorators'=>Array(
'ViewHelper',
'Errors',
),
'validators' => array(
array('validator' => 'StringLength', 'options' => array(0, 20))
)
));
Controller AuthController function loginAction()
$captcha = new Zend_Session_Namespace('captcha');
$captcha->captcha = session_id();
if($dataform['vercode'] != $_SESSION["vercode"]){
$msg="Please enter a correct code!";
$this->view->assign('msg', $msg);
return false;
}
Related
I have created an application in CodeIgniter. I'm trying to insert validation in a form. As I will have many forms in my application, so I'm trying to do it with validation config file.
I have created config file in application/config/form_validation.php. I have also autolaoded config file by adding $autoload['config'] = array('form_validation');
Still, my Validation is not working properly it is always returning boolean false
Below code for the same
form_validation.php file
<?php
$config= array(
'Reservation' => array(
array(
'field' => 'name',
'label' => 'Name',
'rules' => 'required|max_length[50]|min_length[4]|trim|htmlspecialchars|alpha'
),
array(
'field' => 'date',
'label' => 'Date',
'rules' => 'required|trim|htmlspecialchars',
'errors'=> ['required'=>'You must provide a %s for the reservation.']
),
array(
'field' => 'no_people',
'label' => 'No of People',
'rules' => 'required|trim|htmlspecialchars'
)
)
);
?>
index.php - View
<div class="book-reservation wow slideInUp" data-wow-duration="1s" data-wow-delay=".5s">
<?php echo "<script>alert('".validation_errors()."')</script>"; ?>
<?php echo form_open('Entry/Reservation'); ?>
<div class="col-md-12 form-left">
<label><i class="glyphicon glyphicon-calendar"></i>Enter Name:</label>
<input type="text" name='name' value="<?php echo set_value('name'); ?>">
</div>
<div class="col-md-3 form-left">
<label><i class="glyphicon glyphicon-calendar"></i> Date :</label>
<input type="date" name='date' value="<?php echo set_value('date'); ?>">
</div>
<div class="col-md-3 form-left">
<label><i class="glyphicon glyphicon-user"></i> No.of People :</label>
<select class="form-control" name='no_people' value="<?php echo set_value('no_people'); ?>">
<option>1 Person</option>
<option>2 People</option>
<option>3 People</option>
<option>4 People</option>
<option>5 People</option>
<option>More</option>
</select>
</div>
</div>
Entry.php - Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Entry extends CI_Controller {
public function __construct()
{
Parent::__construct();
$this->load->model('Restaurant');
}
public function index()
{
$this->load->view('index');
}
public function Reservation()
{
var_dump($this->form_validation->run('Reservation'));
die;
if($this->form_validation->run() == FALSE)
{
redirect();
}
else
{
#getting values of form
$data['a'] = array(
'Person_Name' => $this->input->post('name'),
'Phone_Number' => $this->input->post('phone'),
'Reservation_Date' => $this->input->post('date'),
'No_People' => $this->input->post('no_people'),
'Reservation_Time' => $this->input->post('time')
);
$data['a'] = $this->security->xss_clean($data['a']); #cleaning data
#calling model
//echo"<pre>";print_r($data['a']);
//die;
if($this->Restaurant->insert_entries($data['a']))
{
$this->session->set_flashdata('message','Your Reservation has accepted, We will call you back shortly.');
redirect();
}
else
{
$this->session->set_flashdata('message','Some techincal issue occured, your reservation did not complete.');
}
}
}
}
Error in below code as it is not redirecting anywhere
if($this->form_validation->run() == FALSE)
{
redirect();
}
Correct Answer:
if($this->form_validation->run() == FALSE)
{
$this->load->view('index');
}
how does one load a div using its id to a view?
this is my view
<div id="register" class="animate form">
<section class="login_content">
<form <?php echo form_open('User/register'); ?>
<h1>Create Account</h1>
<div class="inputlogin">
<div class="form-group">
how will i pass it to
if ($this->form_validation->run() === false) {
// validation not ok, send validation errors to the view
$index['title']="Welcome to Hoovie";
$index['mainContent']="login";
$index['results'] = $this->users_model->get_category();
$this->load->view('includes/redirect', $index, $data);
First, form_open tag makes <form> so you can't echo it inside of form it would look like <form <form>>
here is example of login form inside of view:
echo form_open('path/to/controller');
echo form_input(array(
'name' => 'username',
'class' => 'form-control input-lg',
'placeholder' => 'username'
));
echo form_password(array(
'name' => 'password',
'class' => 'form-control input-lg',
'placeholder' => 'password'
));
echo form_submit(array(
'name' => 'LoginSubmit',
'class' => 'btn btn-lg btn-info',
'value' => 'Login'
));
echo form_close();}
After that inside of your controller you have to activate form_validation library if it is not auto-loaded and then you have to set rules for your inputs
example :
$dugme = $this->input->post('LoginSubmit');
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if(isset($dugme) && $this->form_validation->run()){
//if everything ok, do something
}
else {
//if validation did not pass load view
$this->load_view('login'); }
and after that inside of view you have to echo errors
//I am using bootstrap so alert-danger will show this div with red background
<?php echo validation_errors('<div class="alert alert-danger">','</div>');?>
you can check more about form validation here :
Codeigniter 3: https://www.codeigniter.com/userguide3/libraries/form_validation.html
Codeigniter 2: https://ellislab.com/codeigniter/user-guide/libraries/form_validation.html
I am having trouble bypassing the $this->form_validation->set_rules("blah") even when i'm writing the correct inputs. (Using data exisiting in the databases). What happens is that whatever input i do, the form_validation->run() seems to always return false. Please Help Me :(
The View Part (The Form that i'm using):
<div class="navbar-form navbar-right">
<?php
$user = array('name' => 'username', 'class' => 'form-control', 'placeholder' => 'Username', 'autocomplete' => 'off');
$pass = array('name' => 'password', 'class' => 'form-control', 'placeholder' => 'Password', 'autocomplete' => 'off');
$button = array('id' => 'loginbutton', 'class' => 'form-control');
echo form_open('bigphloginc/validateUser');
?>
<div class="form-group">
<?php echo form_input($user); ?>
</div>
<div class="form-group">
<?php echo form_password($pass); ?>
</div>
<div class="form-group">
<?php
echo form_submit($button,'Login');
echo form_close();
?>
</div>
</div>
The Controller i'm Using:
public function validateUser(){
//Gets the posted values
$tempUsername = $this->input->post('username');
$tempPassword = $this->input->post('password');
//Set the rules for forms
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|md5');
if($this->form_validation->run()==FALSE){ //If the form data isn't accepted, loads back to login
redirect(bigphloginc/index);
}else{ //If form data is accepted, checks the database
if(isset($this->session->userdata($tempUsername))){
redirect(bigphloginc/index);
}else{
$this->load->model('bigphuser');
$query = $this->bigphuser->login($tempUsername,$tempPassword);
if($query==FALSE){ //If the form data doesn't exist in db, loads back to login
$this->load->view('warning');
$this->load->view('ilogin');
}else{ //If the form data exist on db, then continues to their respective pages
$data = array(
'username' => $tempUsername,
'password' => $tempPassword,
'type' => $query[0]->type,
'employeeNumber' => $query[0]->employeeNumber,
'loggedIn' => true
);
$this->session->set_userdata($data); //Sets the data to the session
if($query[0]->type=="admin"){ //if the user is an admin
redirect('bigphadmin/home');
}else if($query[0]->type=="employee"){
redirect('bigphemployee/home'); //if the user is an employee
}//Query Type
}//Query false
}
}//validation false
}
xss_clean is no longer part of form validation in codeigniter 3. The alternative is not to use it, as xss_clean is doing sanitization and not validation.
xss_clean is part of security helper.You can use it as
$this->load->helper('security');
$value = $this->input->post('formvalue', TRUE); //TRUE enables the xss filtering
Check this link for more detail
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.
I'm just learning Yii a few days ago to developer a website for company. Now i have some issue with Yii pagination and i really need your help.
Currently i can make Yii pagination. However, i need to create a button besides pagination area. Everytime, i click that button, it will call ajax to load next page or previous pages (if current page is last page).
Here is my model:
public function getListDesc()
{
$arrPlace = array(0 => '--- --- --- ---');
$criteria=new CDbCriteria;
$criteria->select='t.*,pi.path path';
$criteria->join='JOIN places_images pi ON t.id=pi.places_id';
$criteria->group = 't.id';
$criteria->compare('t.deleted', '<>1', false);
$criteria->compare('t.status',1);
$criteria->compare('outlet','Outlet 1');
$criteria->order = 't.id DESC';
return new CActiveDataProvider('Places', array(
'criteria'=>$criteria,
'pagination' => array(
'pageSize' => 2
)
));
}
Here is a part of my index page which is call that model:
<?php
$this->widget('zii.widgets.CListView', array(
'id' => 'places-list-right',
'dataProvider'=> Places::model()->getListAsc(),
'summaryText'=>'',
'pager' => array(
'header' => '',
'prevPageLabel' => '<<',
'nextPageLabel' => '>>',
),
'itemView'=>'_fea_oulet',)
);
?>
Here is _fea_oulet.php file:
<div class="place_img" id="<?=$data->id?>">
<div class="plusimage">
<a href="javascript:void(0);" onclick="randnew();">
<img alt="<?=$data->id?>" src="<?php echo Yii::app()->request->baseUrl; ?>/images/9life-show-more-images.png" style="border:none;border-radius:0;-webkit-border-radius: 0; -moz-border-radius:0">
</a>
</div>
<?php echo CHtml::image("timthumb.php?src=".$data->path."&w=294&h=294&zc=1&q=100",$data->title);?>
<div class="featitle">
<h3><span><?php
if(strlen($data->title) > 30) {
echo CHtml::encode(mb_substr($data->title,0,30,'UTF-8')) . '...';
}
else{
echo CHtml::encode($data->title);
}
?></span>
<img src="<?php echo Yii::app()->request->baseUrl; ?>/images/9life-show-more-green.png" style="border:none;border-radius:0;-webkit-border-radius: 0; -moz-border-radius:0">
</h3>
</div>
</div>
Any help are appreciates.
Thanks,
You can override CLinkPager class and use your own implementation MyLinkPager in your CListView widget's call specifying its pager property like this:
$this->widget('zii.widgets.CListView', array(
'id' => 'places-list-right',
'dataProvider' => Places::model()->getListAsc(),
'summaryText' => '',
'pager' => array(
'class' => 'MyLinkPager',
'header' => '',
'prevPageLabel' => '<<',
'nextPageLabel' => '>>',
),
'itemView' => '_fea_oulet'
));
run() method of CLinkPager is the place where pager buttons' rendering happens so you can override this method directly. Or you can override createPageButtons() method by adding your custom button to $buttons array if you want to see it along with other page buttons.