Warning: Illegal string offset 'tag' - tags

I am getting this warning on the below line, any help?
<label class="inputLabel"<?php echo ($field['tag']) ? ' for="'.$field['field']['tag'].'"': ''; ?>><?php echo $field['title']; ?></label> **strong text**
Below is the section of the code.
<div class="discountForm<?php echo $selectionStyle; ?> discount<?php echo $box; ?>">
<fieldset class="discount">
<legend><?php echo $selection[$i]['module']; ?></legend>
<?php echo $selection[$i]['redeem_instructions']; ?>
<div class="gvBal larger"><?php echo $selection[$i]['checkbox']; ?></div>
<div class="gvBal">
<?php foreach ($selection[$i]['fields'] as $field) { ?>
<label class="inputLabel"<?php echo ($field['tag']) ? ' for="'.$field['field']['tag'].'"': ''; ?>><?php echo $field['title']; ?></label>
<?php echo $field['field']; ?>
<?php } ?>
<?php if ( ($selection[$i]['module'] != MODULE_ORDER_TOTAL_INSURANCE_TITLE) && ($selection[$i]['module'] != MODULE_ORDER_TOTAL_SC_TITLE) ) { ?>
<div class="buttonRow"><?php echo zen_image(zen_output_string($template->get_template_dir(BUTTON_IMAGE_UPDATE, DIR_WS_TEMPLATE, $current_page_base, 'buttons/' . $_SESSION['language'] . '/') . BUTTON_IMAGE_UPDATE), BUTTON_UPDATE_ALT, '', '', 'onclick="updateForm();"'); ?></div>
<?php } ?>
</div>
</fieldset>

You're trying to access a string using an index that is a string.
You are treating $field as an array while it is actually a string. Check your code and what is the $selection[$i]['fields'] output.

Related

Codeigniter redirect to empty form

I have the follow form in Codeigniter:
The controller:
public function item($alias = NULL){
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Edit menu';
$data['menu_item'] = $this->menu_model->get_menu($alias);
$data['articole'] = $this->menu_model->get_articole();
$data['menuactive'] = $this->menu_model->get_menuactiv();
$data['errors'] = $this->form_validation->error_array();
$this->form_validation->set_rules('position','Position','required');
$this->form_validation->set_rules('position','Position','numeric');
$this->form_validation->set_rules('name','Name','required');
if ($this->form_validation->run() === FALSE) {
$data['name'] = $data['menu_item']['name'];
$this->load->view('templates/header', $data);
$this->load->view('templates/youarehere', $data);
$this->load->view('templates/menu', $data);
$this->load->view('templates/admin', $data);
$this->load->view('menu/item', $data);
$this->load->view('templates/footer');
}
else {
$this->menu_model->update_menu();
redirect('menu');
}
}
The item view is:
<?php echo validation_errors(); ?>
<?php echo form_open('menu/item'); ?>
<?php echo form_label('ID ', 'id'); ?>
<?php echo form_input('id', $menu_item['id'], 'readonly'); ?><br><br>
<?php echo form_label('Name ', 'name'); ?>
<?php echo form_input('name', $menu_item['name']); ?><br><br>
<?php echo form_label('Position ', 'position'); ?>
<?php echo form_input('position', $menu_item['position']); ?><br><br>
<?php foreach($articole as $articole_item):
$articol1[] = $articole_item['id'] . ' ' . $articole_item['title'];
endforeach; ?>
<?php echo form_label('Associated article ', 'associated_article'); ?>
<?php echo form_dropdown('associated_article', $articol1, $menu_item['articol_asociat']); ?><br><br>
<?php echo form_label('Menu activ ', 'activ'); ?>
<?php echo form_checkbox('activ', '1', TRUE); ?><br><br>
<input type="submit" name="submit" value="Save menu"/>
</form>
In this view I edited menu items. Everything works fine when when everything is right. When I introduce something wrong in a field, like string into "position" field, the form redirect to item view, but with empty fields and with the error message. I want to keep what is entered in field and the error message.
What is wrong with my code?
Change your form :
<?php echo form_label('ID ', 'id'); ?>
<?php echo form_input('id', set_value('id'), 'readonly'); ?><br><br>
<?php echo form_label('Name ', 'name'); ?>
<?php echo form_input('name', set_value('name')); ?><br><br>
<?php echo form_label('Position ', 'position'); ?>
<?php echo form_input('position', set_value('position')); ?>
set_value() replace your old values

How to set checked for all selected checkboxes

I have many checkboxes. I want when user clicks submit button and he hasn't filled all required fields, these checkboxes that he has checked, to be checked. My code is the following, but when form submit, only last checkbox is cheked.
function teachers_show(yes, no){
$(".toggle, .all_teachers_show, .student, .school, .teacher_school, .teacher, .class, .teacher_class").hide();
if (no)
$('.all_teachers_show').show();
else
$('.all_teachers_show').hide();
$(":radio").prop('checked',false);
$(yes).prop('checked',true);
}
<?php
echo validation_errors();
echo "<div class='container' id='register_container'>";
echo form_open('home/register');
echo "<table border = '0' >";
echo "<tr><td><label> Username:* </label></td><td>";
$data=array(
'name' => 'username',
'class' => form_error('username') ? 'error' : '',
'value' => set_value('username')
);
echo form_input($data);
echo "</td></tr>";
echo "<tr><td><label> Password:* </label></td><td>";
$data=array(
'name' => 'password',
'class' => form_error('password') ? 'error' : ''
);
echo form_password($data);
echo "<tr><td><label> Choose role:* </label> </td><td>";
$selected_role = $this->input->post('role_id'); ?>
<input type="radio" name="role_id" id="radio1" onclick="showHide(this, true)" value="1"
<?php echo '1' == $selected_role ? 'checked="checked"' :
'' ?>/>
<?php echo " Role 1"; ?>
<input type="radio" name="role_id" id="radio2" onclick="showHide(this, true)" value="2"
<?php echo '2' == $selected_role ? 'checked="checked"' :
'' ?>/>
<?php echo " Role 2 "; ?>
<input type="radio" name="role_id" id="radio5" onclick="teachers_show(this, true)" value="5"
<?php echo '5' == $selected_role ? 'checked="checked"' :
'' ?>/>
<?php echo " Role 3 ";
echo "</td></tr>";
<?php
echo "<tr class='all_teachers_show' style='display:none;'><td><label> Teachers:* </label></td><td>";
?>
<table border='0'>
<tr>
<?php
$ind = 0;
foreach ($all_teachers_show as $row) {
$ind++;
?>
<td>
<?php $selected_teachers = $this->input->post('all_teachers_show[]'); echo $selected_teachers; ?>
<input type="checkbox" id='all_teachers_show' <?php echo set_checkbox('all_teachers_show',$row->user_id); ?> name="all_teachers_show[]"
value="<?= $row->user_id ?>" <?php if ( isset($selected_teachers[$row->user_id] ))
echo 'checked="checked"'; ?>><?= $row->first_name . ' ' . $row->last_name ?> <td>
<?php
if($ind % 3 == 0)
echo '</tr> <tr>';
} ?>
</table>
<?php
echo "</td></tr>";
echo "</div>";
echo "</table><br/>";
$data=array(
"name" => 'mysubmit',
'class' => 'btn btn-success ',
'id' => 'reg',
'value' => 'Register'
);
echo form_submit($data);
?>
</form>
That's my whole code. These chechboxes are for Role 3 - radio button with id='radio5'.
How could it be my if: <?php echo $selected_teachers == $row->user_id ? 'checked="checked"' :
'' ?>
$selected_teachers - it returns array and I compare it with $row->user_id
How could be done that?
try this:
<?php
foreach ($all_teachers_show as $row)
{
$userId = $row->user_id;
$first_name = $row->first_name;
$last_name = $row->last_name;
$teacherSelected = ( isset($_POST[$userId]) ) ? true : false;
?>
<td>
<input
type="checkbox"
class='all_teachers_show'
name="<?php echo $userId; ?>"
<?php
if ( $teacherSelected )
echo 'checked="checked"';
?>
value="<?php echo $userId; ?>"
>
<?php echo $first_name . ' ' . $last_name ?>
<td>
<?php
}

Can't display date in wp_query

I used <?php echo get_the_date( 'd.m.Y' ); ?> to display the date on my other pages, but I have dried the_time()l, the_date() etc. and none of these seem to work to display the date in my post.
I used wp_query to display the posts, but I can't get the date to show. Does anyone have a solution?
<?php
$args = array(
'posts_per_page' => '-1',
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $quicksand_categories
);
$query = new WP_Query( $args );
foreach ($query->posts as $item) {
$categories = wp_get_post_categories($item->ID);
?>
<li id="item" class="item" data-id="id-<?php echo $item->ID ?>" data-type="<?php foreach ($categories as $c) { echo $c . ' ';}?>" >
<div class="article_info">
<h3>
<?php if(get_option('titles') == 'yes') { ?>
<a href="<?php echo get_permalink($item->ID); ?>">
<?php echo get_the_title($item->ID); ?>
</a>
<?php } ?>
/ <?php $cat_id = $c; $cat_name = get_cat_name( $cat_id ); echo $cat_name;?>
</h3>
<span class="post_date"><?php echo get_the_date( 'd.m.Y' ); ?></span>
</div>
<?php if (get_option('featured') == 'yes') { ?>
<a href="<?php echo get_permalink($item->ID); ?>">
<?php echo get_the_post_thumbnail($item->ID,'full'); ?></a>
<?php } ?>
<br />
<p><?php $post = get_post($item->ID); echo $post->post_excerpt; ?></p>
<a href="<?php echo get_permalink($item->ID); ?>">
<img src="<?php bloginfo('template_url');?>/images/viemore_photos.png" alt="View More photos"/>
</a>
</li>
<?php } ?>

zend paginator invalid url

I trying use zend paginator in my project.
And i have problem-when i trying use paginator in news controller, i have links in paginator on index controller!
<?php
class NewsController extends Zend_Controller_Action
{
/**
*
* #var Model_News_Gateway
*/
protected $_newsGateway;
protected $_newsPerPage = 10;
public function init()
{
$this->_newsGateway = new Model_News_Gateway();
}
public function indexAction()
{
$crit = new ExtZF_Model_Criteria();
$crit->addWhere('active', true);
$crit->addDescOrderBy('publish_date');
$paginator = new Zend_Paginator($this->_newsGateway->getPaginatorAdapter($crit));
$paginator->setCurrentPageNumber($this->_getParam('page', 0));
$paginator->setItemCountPerPage($this->_newsPerPage);
$this->view->paginator = $paginator;
}
In view
$this->paginationControl($this->paginator, 'Sliding', '_partials/paginator/default.phtml');
And in default
<?php if ($this->pageCount && count($this->pagesInRange) > 1): ?>
<!--noindex-->
<div class="paginationControl">
(<?= $this->firstItemNumber ?>-<?= $this->lastItemNumber?>/<?= $this->totalItemCount ?>)
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
< <?= $this->translate('previous') ?>
</a> |
<?php else: ?>
<span class="disabled">< <?= $this->translate('previous') ?></span> |
<?php endif; ?>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<a href="<?php echo $this->url(array('page' => $page)); ?>">
<?php echo $page; ?>
</a> |
<?php else: ?>
<?php echo $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('page' => $this->next)); ?>">
<?= $this->translate('next') ?> >
</a>
<?php else: ?>
<span class="disabled"><?= $this->translate('next') ?> ></span>
<?php endif; ?>
</div>
<!--/noindex-->
<?php endif; ?>
I am trying use one default paginator for don't same controllers, but i always have links in paginator like /index/index/page/2.
I need links like /news/index/page/2
But i always have links /index/index/page/2
And i in news controller now. I don't understand why it don't work.
<?
//Ужасный хак, мне стыдно за него
$controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
function replaceController ($search, $replace, $text)
{
$pos = strpos($text, $search);
$secondPos =strpos ($text, $search, $pos+1);
if ($secondPos !== false) {
return $pos !== false ? substr_replace($text, $replace, $pos, strlen($search)) : $text;
} else {
return $text;
}
}
?>

how to convert zend_paginator to ajax in zend framework

this is my action,currently my page is refreshing i want it with ajax.so that without refreshing the whole page my pagination div is refeshing loading the content from DB.
public function calllogsAction(){
if(!Zend_Auth::getInstance()->hasIdentity()){
$this->_redirect('login/login');
}
else{
$request = $this->getRequest();
$phone_service_id = $request->getParam("id");
$registry = Zend_Registry::getInstance();
$DB = $registry['DB'];
$sql ="SELECT caller_name,call_number,call_start_time,call_duration,call_direction FROM CALL_LOG WHERE phone_service_id = $phone_service_id";
$result = $DB->fetchAll($sql);
$page=$this->_getParam('page',1);
$paginator = Zend_Paginator::factory($result);
$paginator->setItemCountPerPage(10);
$paginator->setCurrentPageNumber($page);
$this->view->paginator=$paginator;
$page = $paginator->getCurrentPageNumber();
$perPage = $paginator->getItemCountPerPage();
$total = $paginator->getTotalItemCount();
$A = ($page - 1) * $perPage + 1;
$B = min($A + $perPage - 1, $total);
$C = $total;
$this->view->assign('url', $request->getBaseURL());
$this->view->assign('total',$total );
$this->view->assign('page',$page );
$this->view->assign('A',$A );
$this->view->assign('B',$B );
$this->view->assign('C',$C );
}
}
and this is my view.i have much more in my view but the pagination is here si i want to refresh this div
<div class="container" id="actualbody" style="margin-left:168px;">
<?php
$sr_no = 1;
foreach($this->paginator as $record){
if($sr_no % 2 == 0){
$style = 'class="even-row"';
}
else{
$style = 'class="odd-row"';
<tr <?php echo $style;?>>
<td class="sorting_1"> <input type="checkbox" /> </td>
<td ><?php if($record->call_direction =="Outgoing"){?> <img src=" <?php echo $this->baseUrl('/assets/images/outgoing.png'); ?> " /> <?php } elseif($record->call_direction =="Missed") {?> <img src=" <?php echo $this->baseUrl('/assets/images/misses.png'); ?> " /> <?php } else { ?> <img src=" <?php echo $this->baseUrl('/assets/images/incoming.png'); ?> " /> <?php }?></td>
<td><?php echo $record->caller_name;?></td>
<td><?php echo $record->call_number;?></td>
<td ><?php echo $record->call_start_time;?></td>
<td ><?php echo $record->call_duration;?></td>
</tr>
<?php $sr_no ++; }?>
<div> Showing <?= $this->A; ?> to <?= $this->B; ?> of <?=$this->C; ?> entries </div>
<div> <?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?></div>
</div>
how can i make my pagination through ajax
this pagination.phtml
<div class="pagination" style="width:100%">
<div style="float:left;width:28%">
</div>
<div style="float:right;width:70%;">
<!-- First page link -->
<?php if (isset($this->previous)): ?>
<span class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default ui-state-disabled">Start</span>
<?php else: ?>
<span class="next fg-button ui-button ui-state-default ui-state-disabled">Start</span>
<?php endif; ?>
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<span class="previous fg-button ui-button ui-state-default ui-state-disabled">Previous</span>
<?php else: ?>
<span class="next fg-button ui-button ui-state-default ui-state-disabled">Previous</span>
<?php endif; ?>
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<span class="fg-button ui-button ui-state-default"><?= $page; ?></span>
<?php else: ?>
<span class="fg-button ui-button ui-state-default ui-state-disabled" ><?= $page; ?></span>
<?php endif; ?>
<?php endforeach; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
<span class="next fg-button ui-button ui-state-default">Next</span>
<?php else: ?>
<span class="next fg-button ui-button ui-state-default ui-state-disabled">Next</span>
<?php endif; ?>
<!-- Last page link -->
<?php if (isset($this->next)): ?>
<span class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default">End</span>
<?php else: ?>
<span class="next fg-button ui-button ui-state-default ui-state-disabled">End</span>
<?php endif; ?>
</div>
edited
i add this code
jQuery(function($){
var container = $('#paged-data-container');
var overlay = $('<div>').addClass('loading overlay');
$('.pagination-control').find('a').live('click', function(){
var href = this.href;
var pos = this.rel == 'next' ? '-120%' : '120%';
if (Modernizr.history) {
history.pushState(location.pathname, '', href);
}
container.find('.data').animate({
left: pos
}, 'slow', function(){
var dataContainer = container.find('.paged-data').addClass('loading');
$.get(href, { format: 'html' }, function(data){
dataContainer.removeClass('loading');
container.html(data);
}, 'html');
});
return false;
});
var initialPath = location.pathname;
$(window).bind('popstate', function(e){
// Prevent popstate handler dealing with initial page load
if (location.pathname == initialPath) {
initialPath = null;
return;
}
container.append(overlay);
$.get(location.pathname, { format: 'html' }, function(data){
container.html(data);
}, 'html');
});
});
also add this code to my controller
public function init(){
$this->_helper->ajaxContext->addActionContext('calllogs', 'html')
->initContext();
}
now my collogs.phtml looks like this
<?php
include_once("header.phtml");
include_once("blue1.phtml");
include_once("sidebar.phtml");
?>
<div id="paged-data-container">
<?php echo $this->render('login/calllogs_page.phtml') ?>
</div>
<?php include_once("footer.phtml"); ?>
and this is my calllogs_page.phtml
<?php $paginationControl = $this->paginationControl(
$this->paginator, 'All', 'pagination.phtml') ?>
old stuff here
<div class="pagination-control">
<div class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix" style="height:35px">
<?php if (count($this->paginator)): ?>
<div class="dataTables_info" style="float:left;"> Showing <?= $this->A; ?> to <?= $this->B; ?> of <?=$this->C; ?> entries </div>
<div class="pagination-control" style="margin-left:173px;">
<?php echo $paginationControl ?>
</div>
now my page is changing in address bar when ever i click on any pagination link but nothing happens than
this is the jquery which
$(function($){
$('.pagination-control').find('a').live('click', function(){
var link = $(this);
var container = link.parents('.paged-data-container');
$.get(link.attr('href'), { format: 'html' }, function(data){
container.html(data);
}, 'html');
return false;
});
});
Follow these tutorials: Zend framework video tutorials
Starting from video 11 Zend_Paginator is introduced. Later on it is modified to use Ajax in another video.
I really recommend that you look into it.