The results of search without gridview doesn't displaying in Yii2 - search

I tried to organize searching form from 2 fields. But it doesn't display the results. It just staying in site/index . Help me please
code from siteController.php
public function actionSearch()
{
$driver = new Driver();
if ($driver->load(Yii::$app->request->post())) {
$driver = Driver::find()
->where(['from' => $driver->from])
->andWhere(['to' => $driver->to])
->all();
return $this->render('search', ['driver' => $driver]);
}
else {
throw new NotFoundHttpException('Input data not found' );
}
}
code from models/Driver.php
<?php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use Yii;
/**
* This is the model class for table "driver".
*
* #property string $id
* #property string $from
* #property string $to
* #property string $data
* #property string $about
* #property string $car
*/
class Driver extends \yii\db\ActiveRecord{
/**
* #inheritdoc
*/
public static function tableName()
{
return 'driver';
}
/**
* #inheritdoc
*/
public function rules()
{
return [
// [['from', 'to', 'data', 'about', 'car'], 'required'],
[['about'], 'string'],
[['from', 'to', 'data', 'car'], 'string', 'max' => 255],
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'from' => 'From',
'to' => 'To',
'data' => 'Data',
'about' => 'About',
'car' => 'Car',
];
}
}
code from site/index.php
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use app\models\Driver;
/* #var $driver app\models\Driver */
?>
<?php
$driver = new Driver;
?>
<div class="row">
<div>
<?php $form = ActiveForm::begin([
'action' => ['site/search']
]); ?>
<div class="row">
<div class="col-xs-5">
<?= $form->field($driver, 'from')->label('От')->textInput(['class' => 'input form-control']) ?>
</div>
<div class="col-xs-5">
<?= $form->field($driver, 'to')->label('До')->textInput(['class' => 'input form-control']) ?>
</div>
<div class="col-xs-2" align="left" style="margin-top: 30px">
<input type="image" src="<?= \Yii::getAlias('#web/images/button_search.png')?>" class="icon_button" alt="Поиск" >
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
code from site/search.php
<?php
use yii\widgets\LinkPager;
$this->title = "Поиск";
$this->registerMetaTag([
'name' => 'description',
'content' => 'driver',
]);
$this->registerMetaTag([
'name' => 'keywords',
'content' => 'driver',
])
?>
<?php if (!$driver) { ?>
<p>Ничего не найдено</p>
<?php } else { ?>
<?php foreach ($driver as $one){
$from = $one -> from;
$to = $one -> to;
$data = $one -> data;
?>
<?php return $this -> render('found_drivers', [
'from' => $from,
'to' => $to,
'data' => $data
]); ?>
<?php }?>
<?php } ?>
and site/found_drivers.php
<div class="one">
<h2><?=$id?></h2>
<hr />
<table class="">
<tr>
<td>
<p><?=$from?></p>
</td>
<td class="right">
</td>
<td class="center">
<p><?=$to?></p>
</td>
</tr>
</table>
<div class="">
<?=$data?> <br>
<div class="clear"></div>
</div>
</div>

You have a form in site/index and it's submitting to the same page. If you want to handle the data of your form in another action you need to add it in your form:
$form = ActiveForm::begin([
'action' => ['site/search']
]);
More info here.
And, as #makie said in the comments, you should use render() instead of include() to render partial views.

Related

how protect wordpress comment form from runnig scripts?

Recentrly we developred a custom theme for our Wordpress website,
and I've used native comment Wordpress system that the code is something like below.
the question is how could we protect comment form from xss attack? it seems that scripts like <script>alert('hi');</script> runs simply on comments form.
any idea?
thank you.
<section>
<main>
<div class="comment-area">
<h2 class="comment-title -pb-20">
number of comments: <span><?php echo get_comments_number(); ?></span>
</h2>
<div class="comment-form">
<h3>Insert you comment here please.</h3>
<?php
$arg = array(
'title_reply' => '',
'comment_notes_before' => '',
'label_submit' => 'submmit',
);
comment_form($arg);
?>
</div>
<?php if (have_comments()) : ?>
<div class="comment-list">
<h1>all comments</h1>
<ul>
<?php
$args = array(
'style' => 'ul',
'callback' => null,
'end-callback' => null,
'type' => 'comment',
'reply_text' => 'reply',
'page' => '',
'per_page' => '',
'avatar_size' => 32,
'reverse_top_level' => true,
'reverse_children' => '',
'format' => 'html5',
'echo' => true,
);
wp_list_comments($args);
?>
</ul>
</div>
<div class="comments-pagination">
<?php if(get_comment_pages_count() > 1 && get_option('page_comments')) : ?>
<div>
<?php previous_comments_link('prev'); ?>
</div>
<div>
<?php next_comments_link('next'); ?>
</div>
<?php endif; ?>
</div><!-- .comments-pagination -->
<?php endif; ?>
</div>
</main>
</section>
add_filter( 'comment_text', 'sanitize_comment' );
function sanitize_comment( $comment_text ) {
$comment_text = sanitize_text_field($comment_text);
return $comment_text;
}

Display Description Category for OPencart 2.0

I used mod bycategory to display products on homepage
Now, im' want display description category(don't product) (on homepage)
Code catalog/controller/module/bycategory.php
<?php
class ControllerModuleBycategory extends Controller {
public function index($setting) {
$this->load->language('module/bycategory');
$data['heading_title'] = $setting['name'];
$data['text_tax'] = $this->language->get('text_tax');
$data['button_cart'] = $this->language->get('button_cart');
$data['button_wishlist'] = $this->language->get('button_wishlist');
$data['button_compare'] = $this->language->get('button_compare');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data['products'] = array();
$filter_data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit'],
'filter_category_id'=>$setting['category']
);
$data['type'] = $setting['type'];
$results = $this->model_catalog_product->getProducts($filter_data);
if ($results) {
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = $result['rating'];
} else {
$rating = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $rating,
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/bycategory.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/module/bycategory.tpl', $data);
} else {
return $this->load->view('default/template/module/bycategory.tpl', $data);
}
}
}
}
And code catalog/view/theme/default/template/module/bycategory.tpl
<?php foreach ($products as $product) { ?>
<?php
if($type=="vertical"){
?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?php
}else{
?>
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
<?php
}
?>
<div class="product-thumb transition">
<div class="image"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></div>
<div class="caption">
<h4><?php echo $product['name']; ?></h4>
<?php if ($product['rating']) { ?>
<div class="rating">
<?php for ($i = 1; $i <= 5; $i++) { ?>
<?php if ($product['rating'] < $i) { ?>
<span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } else { ?>
<span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['price']) { ?>
<p class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
<?php } ?>
</p>
<?php } ?>
</div>
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-heart"></i></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-exchange"></i></button>
</div>
</div>
</div>
<?php } ?>
</div>
How to display [![description for category][1]][1] (by category in homepage)?
Help me!
Link demo http://duhocaaumy.com/demo.jpg
Try this solution,
Add below code in catalog/controller/module/bycategory.php
$category_info = $this->model_catalog_category->getCategory($setting['category']);
$data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
Go to catalog/view/theme/default/template/module/bycategory.tpl
Add below code where you want to display category description
<?php echo $description; ?>

How to save table in opencart module?

I am try this code on
admin/view/template/module/test.tpl
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-featured" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<i class="fa fa-reply"></i></div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-featured" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-name"><?php echo $entry_name; ?></label>
<div class="col-sm-10">
<input type="text" name="name" value="<?php echo $name; ?>" placeholder="<?php echo $entry_name; ?>" id="input-name" class="form-control" />
<?php if ($error_name) { ?>
<div class="text-danger"><?php echo $error_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
<div class="col-sm-10">
<select name="status" id="input-status" class="form-control">
<?php if ($status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } ?>
</select>
</div>
</div>
<table id="modules" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="text-left"><?php echo $entry_name; ?></td>
<td></td>
</tr>
</thead>
<tbody>
<?php $module_row = 0; ?>
<?php foreach ($test_modules as $test_module) { ?>
<tr id="module-row<?php echo $module_row; ?>">
<td class="text-right"><input type="text" name="test_module[<?php echo $module_row; ?>][name]" value="<?php echo $test_module['name']; ?>" placeholder="<?php echo $entry_name; ?>" class="form-control" /></td>
<td class="text-left"><button type="button" onclick="$('#module-row<?php echo $module_row; ?>').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
</tr>
<?php $module_row++; ?>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td colspan="1"></td>
<td class="text-left"><button type="button" onclick="addModule();" data-toggle="tooltip" title="<?php echo $button_module_add; ?>" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
</tr>
</tfoot>
</table>
</form>
</div>
</div>
</div>
<script type="text/javascript"><!--
var module_row = <?php echo $module_row; ?>;
function addModule() {
html = '<tr id="module-row' + module_row + '">';
html += ' <td class="text-right"><input type="text" name="test_module[' + module_row + '][name]" value="" placeholder="<?php echo $entry_name; ?>" class="form-control" /></td>';
html += ' <td class="text-left"><button type="button" onclick="$(\'#module-row' + module_row + '\').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
html += '</tr>';
$('#modules tbody').append(html);
module_row++;
}
//--></script>
and try this code on admin/controller/module/test.php
<?php
class ControllerModuleTest extends Controller {
private $error = array();
public function index() {
$this->load->language('module/test');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('extension/module');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
if (!isset($this->request->get['module_id'])) {
$this->model_extension_module->addModule('test', $this->request->post);
} else {
$this->model_extension_module->editModule($this->request->get['module_id'], $this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_name'] = $this->language->get('entry_name');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
$data['button_module_add'] = $this->language->get('button_module_add');
$data['button_remove'] = $this->language->get('button_remove');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['name'])) {
$data['error_name'] = $this->error['name'];
} else {
$data['error_name'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')
);
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/test', 'token=' . $this->session->data['token'], 'SSL')
);
} else {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/test', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], 'SSL')
);
}
if (!isset($this->request->get['module_id'])) {
$data['action'] = $this->url->link('module/test', 'token=' . $this->session->data['token'], 'SSL');
} else {
$data['action'] = $this->url->link('module/test', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], 'SSL');
}
$data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$module_info = $this->model_extension_module->getModule($this->request->get['module_id']);
}
$data['token'] = $this->session->data['token'];
if (isset($this->request->post['name'])) {
$data['name'] = $this->request->post['name'];
} elseif (!empty($module_info)) {
$data['name'] = $module_info['name'];
} else {
$data['name'] = '';
}
if (isset($this->request->post['status'])) {
$data['status'] = $this->request->post['status'];
} elseif (!empty($module_info)) {
$data['status'] = $module_info['status'];
} else {
$data['status'] = '';
}
if (isset($this->request->post['test_module'])) {
$test_modules = $this->request->post['test_module'];
} elseif (isset($this->request->get['test_id'])) {
$test_modules = $this->config->get('test_module');
} else {
$test_modules = array();
}
$data['test_modules'] = array();
foreach ($test_modules as $test_module) {
$data['test_modules'][] = array(
'name' => $test_module['name']
);
}
$this->load->model('design/layout');
$data['layouts'] = $this->model_design_layout->getLayouts();
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('module/test.tpl', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'module/test')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
$this->error['name'] = $this->language->get('error_name');
}
return !$this->error;
}
}
But after save it not saved the values of table .
I am not getting whats the wrong in this code.
Any one please help me.
Thanks
There is two mistakes in your code
1st - Opencart version 2 don't have add module option to layout option in modules. It's moved to layout now. So you can remove your code now,
2nd - In this version to save values to config your module/ shipping/ payment or others extensions input type name must have prefix of module name so your name must be "test_name" here.

How to perform search in yii?

I have a manage quotations page. I need a search based on quotation name and project customer in drop down. With respect to quotation name, I got right search. But drop down user search is not working correctly. The drop down is using another model. The code I followed is given below:-
manageprojects.php
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form">
<?php $this->renderPartial('_search',array(
'model'=>$bots,
'modell'=>$model,
)); ?>
</div>
_search.php
<?php
/* #var $this QuotationsController */
/* #var $model Aquotations */
/* #var $form CActiveForm */
?>
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<style>
.row1{width:auto; overflow:hidden;}
.row20{width:20%;display:inline-block;}
</style>
<div class="row1">
<div class="row20">
<?php echo $form->label($model,'Quotation Serial No'); ?>
<?php echo $form->textField($model,'serial_no'); ?>
</div>
<div class="row20">
<?php echo $form->label($model,'Project'); ?>
<?php echo $form->textField($model,'project_id',array('size'=>60,'maxlength'=>255,'id' =>'projectsid','onkeyup' => "searchcprojects()")); ?>
<div id="searchresult" style="background:#90EE90;"></div>
</div>
<div class="row20">
<?php echo $form->label($model,'Select User'); ?>
<?php echo CHtml::dropDownList('user_id', $model->id, CHtml::listData($model::model()->findAll(array('order' => 'name')), 'id', 'name'), array('empty' => 'Select User', 'class' => 'span12')); ?>
</div>
<div class="row20">
<?php echo CHtml::submitButton('Search', array("class" => "btn btn-danger")); ?>
</div>
</div><!--row1-->
<?php $this->endWidget(); ?>
project Controller
$model = new Acustomers();
$bot=new Aquotations('search');
$bot->unsetAttributes(); // clear any default values
if(isset($_GET['Aquotations'])){
$bot->attributes=$_GET['Aquotations'];
}
$this->render('managequotations',array(
'bots' => $bot,
'model' => $model,
You need to use the activeDropDownList not the dropDownList:
<?php echo CHtml::activeDropDownList($model, 'user_id',
CHtml::listData(User::model()->findAll(array('order' => 'name')),'id','name'),
array('empty' => 'Select User', 'class' => 'span12'));
?>

Custom loop next and previous post links not working

I'm using WP Events Manager and Advanced Custom Fields to develop a site, I have a custom post type called 'event' which I want to display via the below:
<article class="col-main col clearfix">
<table>
<tr>
<th>Cours</th>
<th>Niveau</th>
<th>Dates</th>
<th>Heures</th>
</tr>
<?php
$args = array(
'post_type' => 'event',
'posts_per_page' => 10,
'paged' => get_query_var('paged'),
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => '_event_start_date');
$loop = new WP_Query( $args );
if($loop->have_posts()):
while ( $loop->have_posts() ) : $loop->the_post();
$EM_Event = em_get_event($post->ID, 'post_id');
?>
<tr>
<td><?php echo $EM_Event->output('#_EVENTLINK'); ?></td>
<td><?php the_field('niveau'); ?></td>
<td><?php if($slug != 'stages-ete'): ?>Chaque: <?php the_field('jours'); echo '<br />'; endif; echo $EM_Event->output('#_EVENTDATES'); ?></td>
<td><?php echo $EM_Event->output('#_EVENTTIMES'); ?></td>
</tr>
<?php endwhile;?>
<?php else: ?>
<tr><td colspan="3"><em>Pas de cours à venir.</em></td></tr>
<?php endif; ?>
</table>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries'); ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »'); ?></div>
</div>
</article>
But it's not displaying the previous and next links. Any ideas?
Thanks
Try adding the arguments this way instead
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'event',
'posts_per_page' => 10,
'paged' => $paged,
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => '_event_start_date');
);

Resources