fancybox code delay on opening - fancybox

I have the following code
jQuery(document).ready(function() {
jQuery("#popup-form-signin").fancybox({
'showCloseButton' : false,
});
<?php if (!isset($_SESSION['popup_subscribe'])) :
$_SESSION['popup_subscribe'] = 1;
?>
jQuery("#popup-form-subscribe").fancybox({
'closeClick' : false,
}).click();
setTimeout(function(){
jQuery("#popup-form-subscribe").click();
}, 20000);
<?php endif; ?>
I need to add a timeout to delay the popup
i found the code
setTimeout( function() {$('#popup-form-subscribe').trigger('click'); },20000);
but i dont know where to put it

I think you just have to remove ".click()" when initialising fancyBox, e.g.:
jQuery("#popup-form-subscribe").fancybox({
'closeClick' : false,
});
setTimeout(function(){
jQuery("#popup-form-subscribe").trigger('click');
}, 20000);

Related

invisible reCAPTCHA javascript

I have the invisible reCAPTCHA set up, but it doesn't seem to want to call my callback function. My form looks like:
<form id='ContactAgentForm' name='ContactAgentForm' class='custom-form-widget-form standard_form' action='contact_agent' listing_id=1233445>
...
<div class='field captcha-field recaptcha_field' >
<div id='g-recaptcha-div' class="g-recaptcha" ></div>
</div>
...
<div class="field button-field">
<button class="button button-primary"><span>Send</span></button>
<a class="button button-cancel btn-close" href="#cancel"><span>Cancel</span></a>
</div>
</form>
In the javascript, I want to handle the fact that there might be multiple forms on the page, so I create a list of all the forms. For each form, I attach/render the reCAPTCHA logic, attaching my callback with the form passed as a parameter:
<script>
var $form_list = jQuery("form.custom-form-widget-form");
var onFormPageSubmit = function(token, $form ) {
console.log("Got here! ", token );
var field = $form.find('.g-recaptcha-response')[0];
field.value = token;
$form[0].submit();
};
var onloadCallback = function() {
$form_list.each( function() {
var $form = jQuery(this);
var $recaptcha = $form.find( ".g-recaptcha" );
if ( $recaptcha.length )
{
var recaptchaId = grecaptcha.render($recaptcha[0], {
'callback': function (token) { onFormPageSubmit(token, $form); },
'sitekey': "{$captcha_config.invisible_captcha_site_key}",
'size': 'invisible',
'badge': 'inline'
});
$form.data("recaptchaid", recaptchaId);
}
});
};
</script>
And just below that, I load the recaptcha/api.js file:
<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=onloadCallback"></script>
With some judicial 'console.log' statements, we get through all of the code EXCEPT for the callback (onFormPageSubmit). The "protected by reCAPTCHA" logo is there, but it seems that the form is just submitted, ignoring the reCAPTCHA call altogether.
All help appreciated.
Somewhere along the line, the validation function for the form was lost (it's in another file). The validation function was attached to the button, and it executed something like this:
$submit_button.on( 'click', function( event ) {
event.preventDefault();
// get the recaptchaid from form data
var $recaptcha_id = $form.data( "recaptchaid" );
if ( $recaptcha_id != undefined )
{
grecaptcha.execute($recaptcha_id);
}
} );
The "grecaptcha.execute" is the important thing - this is what triggers the actual reCAPTCHA call.

codeigniter form_validation with ajax

When i submit it with no data, it shows like this. but i want it to show on my modal, because i'm using the form_validation library.
enter image description here
This is my Controller:
$this->form_validation->set_rules('category_name','Category name','trim|required');
if($this->form_validation->run() == FALSE){
echo validation_errors();
} else{
$category = array(
"category_name" => $this->input->post('category_name')
);
$this->category_m->insert($category);
echo "Successfully Added.";
}
This is my ajax file:
$(document).on('submit', '#form' ,function(event){
event.preventDefault();
var form = $(this).serialize();
$.ajax({
url:"<?php echo base_url(); ?>category/operation",
type:"POST",
data:form,
success:function(data){
$('#form')[0].reset();
$('#mymodal').modal('hide');
$('#alert').fadeIn().html('<div class="alert alert-info">'+data+'</div>').fadeOut(5000);
table.ajax.reload();
}
})
});
This is not related to Codeigniter. It's JS/jQuery/HTML/...
Assuming that you have something like this in your HTML
<div id="mymodal">...</div>
Create another div#alert inside
<div id="alert">...</div>
And change the Javascript to something like
//You don't neet fadeIn/fadeOut
$('#alert').html('<div class="alert alert-info">'+data+'</div>');
$('#mymodal').modal('show');

How to set id for AJAX

I have following Jquery-Script, which works fine outside of yii2
<script>
$(function () {
$(".comment_button").click(function () {
var element = $(this);
var test = $("#_id_").val();
var dataString = '_id_=' + test;
if (test == '')
{
alert("No record, no action...!");
} else
{
$.ajax({
type: "POST",
url: '<?=\Yii::$app->urlManager->baseUrl?>/insert.php',
//url: 'insert.php',
data: dataString,
cache: false,
/*
success: function (html) {
$("#display").after(html);
document.getElementById('_id_').value = '';
*/
}
});
}
return false;
});
});
</script>
It works,'cause I have following html input box:
<textarea cols="30" rows="2" style="width:480px;font-size:14px; font-weight:bold" id="_id_" maxlength="145" ></textarea>
As u can see, jquery will take id= _ id _ in order to use AJAX.
I try to realize same thing with yii2, but I get following error:
bewerber_update?id=2:1925 Uncaught TypeError: Cannot set property 'value' of null
at Object.success (bewerber_update?id=2:1925)
at fire (jquery.js:3187)
at Object.fireWith [as resolveWith] (jquery.js:3317)
at done (jquery.js:8757)
at XMLHttpRequest.<anonymous> (jquery.js:9123)
This error will be thrown out,' cause I don't konw, how to set id correctly in yii2. I tried like this, but this is obviously the wrong way:
<?=
$form->field($model, 'beurteilung_fachlich')->widget(\dosamigos\ckeditor\CKEditor::className(), [
'id'=>'_id_',
'options' => ['rows' => 1],
'preset' => 'full'
])
?>
Any ideas, how to set id in a correct way?
You should pass id in options
<?= $form->field($model, 'beurteilung_fachlich')->widget(\dosamigos\ckeditor\CKEditor::className(), [
'options' => ['rows' => 1, 'id' => '_id_'],
'preset' => 'full'
]) ?>

how multiple row delete using checkbox in yii2

How can I use in GridView delete selected object,in Yii 2 Framework such as following image:
[enter image description here][2]
Try this
<?=Html::beginForm(['controller/bulk'],'post');?>
<?=Html::dropDownList('action','',[''=>'Mark selected as: ','c'=>'Confirmed','nc'=>'No Confirmed'],['class'=>'dropdown',])?>
<?=Html::submitButton('Send', ['class' => 'btn btn-info',]);?>
<?=GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\CheckboxColumn'],
'id',
],
]); ?>
<?= Html::endForm();?>
This is the controller:
public function actionBulk(){
$action=Yii::$app->request->post('action');
$selection=(array)Yii::$app->request->post('selection');//typecasting
foreach($selection as $id){
$e=Evento::findOne((int)$id);//make a typecasting
//do your stuff
$e->save();
}
}
Or Else
Follow all the steps given in this Link, You will Surely achive your goal.
Yii 2 : how to bulk delete data in kartik grid view?
https://stackoverflow.com/questions/27397588/yii-2-how-to-bulk-delete-data-in-kartik-grid-view/
You can use a column with checkboxes and bulk actions for each row selected.
Here is a related question:
Yii2 How to properly create checkbox column in gridview for bulk actions?
<?php
$url = Url::to(['user/delete']);
$this->registerJs('
$(document).on("click", "#delete_btn",function(event){
event.preventDefault();
var grid = $(this).data(\'grid\');
var Ids = $(\'#\'+grid).yiiGridView(\'getSelectedRows\');
var status = $(this).data(\'status\');
if(Ids.length > 0){
if(confirm("Are You Sure To Delete Selected Record !")){
$.ajax({
type: \'POST\',
url : \''.$url.'\' ,
data : {ids: Ids},
dataType : \'JSON\',
success : function($resp) {
if($resp.success){
alert(resp.msg);
}
}
});
}
}else{
alert(\'Please Select Record \');
}
});
', \yii\web\View::POS_READY);
?>
[1]: http://i.stack.imgur.com/iFjT1.png
I have succeeded in deleting multiple rows in gridview Yii2 by doing the following:
Create button in index.php
<p>
<button type="button" onclick="getRows()" class="btn btn-success">Delete Bulk</button>
</p>
Add javascript code in index.php to perform the event of getting the checked rows from the GridView widget.
<script>
function getRows()
{
//var user_id as row_id from the gridview column
// var list = [] is an array for storing the values selected from the //gridview
// so as to post to the controller.
var user_id;
var list = [];
//input[name="selection[]"] this can be seen by inspecting the checkbox from your //gridview
$('input[name="selection[]"]:checked').each(function(){
user_id = this.value;
list.push(user_id);
});
$.ajax({
type: 'post',
url:'index.php?r=student-detail-update/bulk',
data: {selection: list},
});
}
</script>
Put this code in your contoller
if ($selection=(array)Yii::$app->request->post('selection')) {
foreach($selection as $id){
$StudentDetailUpdates = StudentDetailUpdate::find()
->where(['user_id' => $id])
->all(); //....put your staff here
}

Netbeans - Syntax Check error using php inside javascript

Netbeans 7.0 is highlighting lines as syntax error when i use PHP inside JavaScript
In my case
<script type="text/javascript">
$(document).ready(function(){
$("#rating_<?=$coObj->company_id?>").jRating({
step: true,
longStarsPath:"include/jrating/jquery/icons/btn_black_trans2.png",
rateMax:1,
phpPath:"include/jrating/php/jRating.php",
<?php
if($_SESSION["rate_of_".$coObj->company_id] == 1)
echo 'isDisabled: true,';
else
echo 'isDisabled: false,';
?>
type:'long',
length : 1,
decimalLength : 0,
rateMax: 1,
onSuccess : function(){
alert('Success : your rating has been saved');
location.reload(true);
},
onError : function(){
alert('Error : please retry');
}
});
});
</script>
all the lines below PHP code are highlighted, and first line says that missing : after property id
#Marek:
I don't really see that as an answer, more of a workaround (which doesn't always work)...
NetBeans should make things easier, not make us change syntax to avoid it failing in the highlighting...
Anyways, I use a lot of mixed Javascript/PHP code, and NetBeans fails miserably all over the place...I also use Notepad++ which doesn't have any problems with this...
Example:
function showUpload<?php echo $upload_number;?>(file) { /*some code*/ }
Or:
$('.option-help').qtip({
content: function(api) { return $(this).parent().attr('data-tip'); },
<?php if ($option_help == 'icon') { ?>
show: { event: 'click' },
<?php } ?>
position: {my: 'bottom left',at: 'top left'}
});
Does anyone know of a better solution to the OP's question?!?
edit your syntax to this:
isDisabled:<?php
if($_SESSION["rate_of_".$coObj->company_id] == 1)
echo 'true';
else
echo 'false';
?>,