Yii bootstrap submit a form inside a modal window using the modal buttons - forms

I'm trying to submit a form from inside a modal window using the modal buttons in the modal-footer.
The form itself is loaded through ajax from a link (controller/action).
Just to be clearer I attached this picture:
This is the code for the modal:
<?php $this->beginWidget('bootstrap.widgets.TbModal', array('id'=>'modal')); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Client Ticket Status Update</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'ajaxSubmit',
'type'=>'primary',
'label'=>'Save changes',
'url'=>'#',
'htmlOptions'=>array('data-dismiss'=>'modal'),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'label'=>'Close',
'url'=>'#',
'htmlOptions'=>array('data-dismiss'=>'modal'),
)); ?>
</div>
<?php $this->endWidget(); ?>
This is the javascript that loads the form inside the modal:
$("a[data-toggle=modal]").click(function(){
var target = $(this).attr('data-target');
var url = $(this).attr('href');
if(url){
$(target).find(".modal-body").load(url);
}
});
This is the form view:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'client-ticket-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required. </p>
<?php echo $form->errorSummary($ticket); ?>
<div>
<?php echo $form->labelEx($ticket,'sent_to'); ?>
<?php echo $form->textField($ticket,'sent_to'); ?>
<?php echo $form->error($ticket,'sent_to'); ?>
</div>
<div>
<?php echo $form->labelEx($ticket,'courier'); ?>
<?php echo $form->textField($ticket,'courier'); ?>
<?php echo $form->error($ticket,'courier'); ?>
</div>
<div>
<?php echo $form->labelEx($ticket,'awb'); ?>
<?php echo $form->textField($ticket,'awb'); ?>
<?php echo $form->error($ticket,'awb'); ?>
</div>
<div>
<?php echo $form->labelEx($ticket,'awb_date'); ?>
<?php echo $form->textField($ticket,'awb_date'); ?>
<?php echo $form->error($ticket,'awb_date'); ?>
</div>
<div class="buttons">
<?php echo CHtml::submitButton($ticket->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Any help is very appreciated. If you require more information, please ask.

Change code at model-footer as below:
<div class="modal-footer">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'type'=>'primary',
'label'=>'Save changes',
'url'=>'#',
'htmlOptions'=>array('onclick' => '$("#formID").submit()'),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'label'=>'Close',
'url'=>'#',
'htmlOptions'=>array('data-dismiss'=>'modal'),
)); ?>

This first response didn't resolve my problem of a modal form closing on submit. For anyone else that is having issues, I had to enable client Validation in the CActiveForm.
It ended up looking like this:
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'feature-form',
'enableAjaxValidation' => true,
'enableClientValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => true,
'validateOnType' => true
)
)
);
Hopefully this helps some coming after me.

just trigger the click event on the other one that you don't want to show, an also hide it first!

Related

Show plain text in Gridview/DetailView

I use kartik/GridView. In my database, I have following record using widget of \dosamigos\ckeditor\CKEditor in _form.php:
<p>ist gewöhnungsbedürftig aber halt auch kompetent</p>
Any ideas how to outline this record in GridView without HTML-tags, just plain text like this:
ist gewöhnungsbedürftig aber halt auch kompetent
Here is my DetailView:
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
?>
<div class="bewerber-view">
<div class="row">
<div class="col-sm-9">
<h2><?= Html::encode($model->id) ?></h2>
</div>
</div>
<div class="col-lg-1">
<?php
$gridColumn = [
.
.
'beurteilung_persoenlich:ntext', //contains upper record
.
.
];
echo DetailView::widget([
'model' => $model,
'attributes' => $gridColumn
]);
?>
</div>
got solution by my own:
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
?>
<div class="bewerber-view">
<div class="row">
<div class="col-sm-9">
<h2><?= Html::encode($model->id) ?></h2>
</div>
</div>
<div class="col-lg-1">
<?php
$gridColumn = [
.
.
'beurteilung_persoenlich:html', //contains upper record
.
.
];
echo DetailView::widget([
'model' => $model,
'attributes' => $gridColumn
]);
?>
</div>
will solve my problem as described.
Happy Coding
this worked for me
'your_attritube_name:html'

How to go to a div with a given ID cakephp3

I am struggling with this problem, I am writing a code for a dashboard but It's not coming together. This is the code currently have:
<?= $this->Html->link('Edit', array('#' => 'container edit', $server->id)) ?>
This is the link to the div right down here, it's working when i don't give the server-id to the specific row. With the ID it doesn't redirect correctly.
<div class="container admin-section admin-sub edit" id="admin-edit">
<nav class="col col-xs-12 col-md-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li data-target="admin-overview">Server List</li>
<li><?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $servers->id],
['confirm' => __('Are you sure you want to delete # {0}?', $servers->id)]
)
?></li>
</ul>
</nav>
<div class="servers form col col-xs-12 col-md-8 columns content">
<?= $this->Form->create($servers) ?>
<fieldset>
<legend><?= __('Edit Server') ?></legend>
<?php
echo $this->Form->input('url', ['class'=> 'form-control']);
echo $this->Form->input('description', ['class'=> 'form-control']);
?>
</fieldset>
<?= $this->Form->button(__('Submit'), ['class'=> 'btn btn-primary']) ?>
<?= $this->Form->end() ?>
</div>
</div>
Instead it'll go to http://dashboard/pages/1#container%20add which it shouldn't be doing. How can I make sure it'll only go to the div and not a different page?
You can do this with Url->Build
exemple:
toto
You can do it by using controller and action name.
Example :
echo $this->Html->link('Title', array(
'controller'=>'pages',
'action'=>'index',
$server->id,
'container edit'
)
);
Above code will produce -
pages/{serverId}#container%20add
pages/index/{serverId}#container%20add

Selected an option in edit view cakephp 3.0

I am generating list within a form like the following code. But for updating view how can select the particular option according to the user. Suppose for this user's role is Customer. Then how can select this(Customer) option in CakePHP 3.
<?= $this->Form->create($user) ?>
<?php
echo $this->Form->input('fullname');
echo $this->Form->input('contact_no');
?>
<div class="form-group">
<?php echo $this->Form->select(
'role',
['Customer', 'Staff', 'User'],
['title' => 'Select user type']
); ?>
</div>
<?= $this->Form->end() ?>
Here is what I did : (According that I have 2 tables : Users which belongsTo Roles)
In my UsersController, i added this following line :
$this->set('roles', $this->Users->Roles->find('list')->order('name'));
Then, you'll need to edit your view from
<div class="form-group">
<?php echo $this->Form->select(
'role',
['Customer', 'Staff', 'User'],
['title' => 'Select user type']
); ?>
</div>
to
<div class="form-group">
<?= $this->Form->select(
'role_id',
$roles,
['id' => 'role-id', 'required' => true]
);
?>
</div>

wp shortcode breaks get_post_thumbnail

I'm having some trouble with short code's breaking a featured image I have set on my home page in Wordpress (4.0). For some reason, when I paste in my shortcode in the wp-admin > page > edit > content for the home page, suddenly my featured image stops working. It's working until I paste in the shortcode and update the page, but then the image disappears and the_post_thumbnail() returns false. I've also tried get_the_post_thumbnail() without success.
Here's my code excerpt from "front-page.php":
<div class="small-12 medium-6 columns">
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
<div class="small-12 medium-6 columns">
<?php if (has_post_thumbnail()) {the_post_thumbnail();} ?>
</div>
And here's the shortcode function from "functions.php":
// [random_testimonial]
function short_code_get_random_testimonial(){
$args = array( 'post_type' => 'testimonial', 'posts_per_page' => 1, 'orderby' => 'rand' );
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
$random_testimonial = get_the_content();
$author = get_the_title();
$rt = '<p class="quote">' . $random_testimonial;
$rt .= '</p><p class="right">– ' . $author . '</p>';
endwhile;
return $rt;
}
// Register the shortcodes.
add_shortcode( 'random_testimonial', 'short_code_get_random_testimonial' );
// Allow text widgets to contain shortcodes.
add_filter('widget_text', 'do_shortcode');
add_filter('the_content', 'do_shortcode');
Any ideas would be greatly appreciated.
I think I may have solved this one. It seems to have something to do with the fact that I was calling a custom post type with the shortcode, so by the time the_post_thumbnail() was called, the query had changed to refer to the custom post type included in the shortcode ("testimonial") rather than the parent post (in this case the home page). I revised my code as follows to catch the image before the shortcode is called, and all is working again:
<div class="small-12 medium-6 columns">
<?php while ( have_posts() ) : the_post(); ?>
<?php
// go ahead and get the post image in case [random_testimonial]
// shortcode is used in page content which will break the query.
if (has_post_thumbnail()) {$image = get_the_post_thumbnail();} ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
<div class="small-12 medium-6 columns">
<?php
// Echo post image from above.
if(isset($image)){echo $image;}
?>
</div>

Zend_Paginator: no page number on links on a page with no page number specified by the URL

Without sticking /1 onto a url is there away to change Zend_Paginator to approach a URL? Currently the user goes to /aaron/studio. Then the user should click through the paging and start accessing URLS such as : /aaron/studio/2
I have this rule:
$router->addRoute('studios/page', new Zend_Controller_Router_Route(':id/studio/:page',array('module' => 'default', 'controller' => 'studio', 'action' => 'view')));
If I go-to /aaron/studio/2, the Paginator links correctly to other pages, if i goto /aaron/studio it doesn't link to other pages, just the page its on.
What I need todo somehow it make Paginator aware that of its location even without a page in the URL.
Heres my controller code if it helps:
$page = $this->_getParam('page', 1);
$from = ($page * $this->clips_per_page) - $this->clips_per_page;
$count = Model_Clip::load_by_type(array('type' => 'studio_id', 'values' => $object->id, 'to' => 0, 'to' => COUNT_HIGH, 'count' => 1, 'order' => 'd.views DESC'));
$paginator = Zend_Paginator::factory($count);
$paginator->setItemCountPerPage($this->clips_per_page);
$paginator->setCurrentPageNumber($page);
$paginator->setPageRange(25);
$this->view->paginator = $paginator;
Edit, heres my view as requested:
<?php if (count($this->paginator) && $this->paginator->count() > 1): ?>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml', array('translate' => $this->translate)); ?>
<?php endif; ?>
and the partial
<div class="pagination-control" style="width: auto; text-align: center; margin: 0 auto">
<div style="width: auto;">
<!-- First page link -->
<?php if (isset($this->previous)): ?>
Start |
<?php else: ?>
<!-- <span class="disabled">Start |</span> -->
<?php endif; ?>
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
Previous |
<?php else: ?>
<!-- <span class="disabled"> Previous |</span> -->
<?php endif; ?>
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?php echo $page; ?>
<?php else: ?>
<span class="chosen"><?php echo $page; ?></span>
<?php endif; ?>
<?php endforeach; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
| Next |
<?php else: ?>
<!-- <span class="disabled">| Next |</span> -->
<?php endif; ?>
<!-- Last page link -->
<?php if (isset($this->next)): ?>
End
<?php else: ?>
<!-- <span class="disabled">End</span> -->
<?php endif; ?>
<p>
Page <?php echo $this->current; ?> of <?php echo $this->last; ?>
</p>
</div>
<p class="clear"></p>
</div>
I had the same problem, and I just figured out that the problem was in the route.
First I had specified the route like this:
$router->addRoute(
'projects',
new Zend_Controller_Router_Route('/:lang/projects/:category/',
array('lang' => 'en',
'module' => 'index',
'controller' =>'projects',
'action' =>'index'
)
)
);
so the paginator was not printing the page numbers when generating the links, when I changed the route and put the :page var the paginator worked. The final route is:
$router->addRoute(
'projects',
new Zend_Controller_Router_Route('/:lang/projects/:category/:page',
array('lang' => 'en',
'module' => 'index',
'controller' =>'projects',
'action' =>'index',
'page' => 1
)
)
);
Try providing a default value of 1 for :page in the router
http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard
(scroll down to Variable Defaults)
$router->addRoute('studios/page',
new Zend_Controller_Router_Route(':id/studio/:page',
array('module' => 'default', 'controller' => 'studio', 'action' => 'view'),
array('page' => 1)));