Im using codeigniter, and I have a double form submission problem. I looked for a solution on google about 2-3 days ago, but I still didn't manage to find one. Can someone help me?
shopping_cart.php
<?php
echo anchor("user/item_all", "Continue to shopping", array(
'class' => 'btn btn-info'
));
if ($this->cart->total_items() > 0):
if ($return_checkout) {
echo anchor("user/checkout", "Checkout", array(
'class' => 'btn btn-success pull-right',
'style' => "margin-left: 10px",
));
}
echo anchor("user/destroy_cart", "Delete All Cart", array(
'class' => 'btn btn-danger',
'style' => "margin: 0px 10px"
));
echo form_button(array(
'type' => 'submit',
'class' => 'btn btn-primary pull-right',
'style' => "margin: 0px 10px",
'content' => "Update Cart"
));
endif;
?>
User.php
function checkout() {
$return_checkout = $this->session->userdata('poin') >= $this->cart->total() ? TRUE : FALSE;
$cart = $this->cart->contents();
if ($return_checkout AND count($cart) > 0) {
if ($this->mall->checkout($cart)) {
$this->cart->destroy();
redirect('user/shop_history');
}
}else
redirect('user/shop_history');
}
I hope someone can help me. Thanks in advance!
Related
I have a gridview with pjax.
<div class="request-index">
<div id="ajaxCrudDatatable">
<?=
GridView::widget([
'id' => 'crud-datatable',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax' => true,
'columns' => require(__DIR__ . '/_columns.php'),
'toolbar' => [
['content' =>
Html::a('<i class="glyphicon glyphicon-plus"></i> Add Request', ['create'], ['role' => 'modal-remote', 'title' => 'Create new Requests', 'class' => 'btn btn-success']) .
Html::a('<i class="glyphicon glyphicon-repeat"></i> Reload', [''], ['data-pjax' => 1, 'class' => 'btn btn-primary', 'title' => 'Reset Grid']) .
'{toggleData}' .
'{export}'
],
],
'panel' => [
'type' => 'primary',
'heading' => '<i class="glyphicon glyphicon-list"></i> Requests listing',
'before' => '<button type="button" class="btn btn-danger btn-secondary"> Belum Selesai : <strong>'. $count_request_belum_selesai .'</strong> </button>',
'after' => BulkButtonWidget::widget([
'buttons' => Html::a('<i class="glyphicon glyphicon-trash"></i> Delete All', ["bulk-delete"], [
"class" => "btn btn-danger btn-xs",
'role' => 'modal-remote-bulk',delete this item'
]),
]) .
'<div class="clearfix"></div>',
]
])
?>
</div>
if you see from code above, please concern with
'before' => '<button type="button" class="btn btn-danger btn-secondary"> Not finished : <strong>'. $count_request_belum_selesai .'</strong> </button>',
When this button is clicked, I want to running a function in my model named RequestSearch :
public function searchRequestBelumSelesai(){
$query = Request::findAll(['tanggal_selesai' => NULL]);
return $query;
}
Which is the gridview will be displayed the result, is it possible ?
In the action of the controller that will receive the click of your button, you must modify the dataProvider given to the View, so that it looks like something like this:
$dataProvider= new ActiveDataProvider([
'query' => $your_model->searchRequestBelumSelesai(),
]);
This code in pic below:
Image:
Actually it deppends on form_submit($data);. But you can make data like this, so you can insert the $data['html'] inside the botton.
$data = array(
'class' => 'btn btn-primary btn-lg btn-myblock',
'name' => 'signin',
'value' => 'Sign In',
'html'=>'<span class="glyphicon glyphicon-user"></span>'
);
?>
<?php echo form_submit($data); ?>
I tried to add extra action buttons. Admin only view this button after button click update in a single field in the database.
<p>
<?php
if(!Yii::$app->user->isGuest ){
echo Html::a('Recommended', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to reject this application?',
'method' => 'post',
],
]);
} else if(Yii::$app->user->can('admin')){
}
?>
</p>
My problem is that I have 3 users that are: applicant, faculty and admin (or hod). In this case after faculty recommendation, the admin (or hod) sanctioned the leave.
I create leave application and faculty recommended, so now I want get the recommended data when admin login to the site.
If admin is the username you should follow this way :
<p>
<?php
if(!Yii::$app->user->isGuest ){
echo Html::a('Recommended', ['update', 'id' => $model->id],
['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to reject this application?',
'method' => 'post',
],
]);
} else if(Yii::$app->user->identity->username == 'admin' ){
echo Html::a('Your Button Label for Admin',
['yourActionForAdmin', 'id' => $model->id],
['class' => 'btn btn-primary']);
}
?>
</p>
I've just started working with CakePHP and I want to create a form that when it is submitted it calls a function in the controller. I'm using CakePHP version 2.6
The Code I currently have is:
view:
<div class="modal-body">
<?php echo $this->Form->create('Tweet', array('url' => array('controller' => 'posts', 'action' => 'postTweet'))); ?>
<?php echo $this->Form->textarea('Tweet', array('class' => 'form-control','rows' => '3', 'placeholder' => "what's happening?", 'maxlength' => '140', 'label' => false)); ?>
<?php echo $this->Form->button('Close', array('class' => 'btn btn-default', 'data-dismiss' => 'modal', 'type' => 'button'));?>
<?php echo $this->Form->submit('Tweet', array('class' => 'btn btn-primary', 'type' => 'submit', 'div' => false)); ?>
<?php echo $this->Form->end(); ?>
</div>
PostsController:
public function postTweet(){
//check if post is being made
if ($this->request->is('post')) {
//do something
}
}
HTML on page:
<form action="/posts/postTweet" id="TweetIndexForm" method="post" accept-charset="utf-8">
<div style="display:none;">
<input name="_method" value="POST" type="hidden">
</div>
<textarea name="data[Tweet][Tweet]" class="form-control" rows="3" placeholder="what's happening?" maxlength="140" id="TweetTweet"></textarea>
<button class="btn btn-default" data-dismiss="modal" type="button">Close</button>
<input class="btn btn-primary" value="Tweet" type="submit">
</form>
The problem is when I click the submit button nothing happens, I've checked in Firebug and no errors are in the console tab, no POST is made in the network tab and there are also no errors logged to the error log. Any help will be great thanks.
EDIT:
Solved I had JavaScript preventing the form from being submitted Thanks for the help!
Use submit like ->
echo $this->Form->submit('Tweet', array('label' => false, 'name' => 'submit', 'class' => 'grayBTN', 'title' => '', 'alt' => 'Submit', 'error' => false));
It works I use it all the time .
The issue with your submit is 'type' => 'submit' is used in your code and you also specify $this->Form->submit too .
If you are specifying Button with type submit then its ok like ->
echo $this->Form->button('Submit Form', array('type' => 'submit'));
But in your case you have $this->Form->submit.. So you dont need to specify it explicitely.
try this
echo $this->Form->end(array('label' => 'Tweet','div' => false,'class' => 'btn btn-primary'));
[below translated from translate.google.com]
I'm looking for the syntax of how to make a button disabled in CakePHP and I can not get a result; My application need to first save a field for a button to finish the whole process after another button. The first button is a submit and redirects to the same page. The second button performs a function of the controller and go to the next process. I want to prevent the user to go to the next procedure without saving the first; I already have a variable that defines whether it is safe or not, just do not know how to make the Finish button is disabled;
Button code:
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array('controller' => 'Questoes','action' => 'limparSession'),
array('role' => 'button', 'class' => 'btn btn-success', 'escape' => false)
);
Add the disabled class to your button:
<?php
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array(
'controller' => 'Questoes',
'action' => 'limparSession'
),
array(
'role' => 'button',
'class' => 'btn btn-success disabled',
'escape' => false
)
);
?>
This is a bootstrap feature related to the given class.
If you want to do it without bootstrap:
<?php
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array(
'controller' => 'Questoes',
'action' => 'limparSession'
),
array(
'role' => 'button',
'class' => 'btn btn-success',
'disabled' => 'disabled',
'escape' => false
)
);
?>
echo $this->Form->button(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok'))." Finalizar",
array('type' => 'submit','onclick' => 'this.disabled=true;return true;',
'class' => 'btn disabled', 'escape' => false)
);