I have a few different contact forms (all using contact form 7) and would like to track the submission action on each of them. In the GA tracking code, I added the following:
ga('send', 'event', 'Forms', 'Submit', 'PFStandard');
ga('send', 'event', 'Forms', 'Submit', 'PFAdvanced');
ga('send', 'event', 'Forms', 'Submit', 'PFTrainer');
ga('send', 'event', 'Forms', 'Submit', 'SnowcatBasic');
ga('send', 'event', 'Forms', 'Submit', 'SnowcatEnhanced');
ga('send', 'event', 'Forms', 'Submit', 'WinterSurvival');
ga('send', 'event', 'Forms', 'Submit', 'GeneralContact');
I also added snippets to individual contact forms. For example, in the winter survival's additional setting, I added:
on_sent_ok: "ga('send', 'event', 'Forms', 'Submit', 'WinterSurvival');"
I thought the labels would track only that form, but instead it's tracking each form submission 7 times... What should I do?
Related
I was wondering whether I can call the action automatically through ajax one by one for each row of the GridView after the page is load.
All I can do now is trigger the call manually through button click, already returned the value correctly.
Here is my GridView:
<?php Pjax::begin(['id' => 'payment-list-view-container', 'timeout' => 5000]); ?>
<?= GridView::widget([
'id' => 'payment-table',
'dataProvider' => $dataProvider,
'resizableColumns' => false,
'tableOptions' => ['class' => 'table table-striped'],
'pjax'=>true,
'pjaxSettings' => [
'options' => [
'id' => 'payment-table',
'enablePushState' => false,
],
],
'columns' => [
[
'class' => 'kartik\grid\SerialColumn',
'header' => 'No.',
],
[
'header' => 'Title',
'attribute' => 'name',
],
[
'attribute' => 'date_start',
'header' => 'Payment Date',
'value' => function($model){
return Yii::$app->formatter->asDatetime($model->payment_date, "php:d F Y");
}
],
[
'header' => 'Action',
'format' => 'raw',
'value' => function($model) use ($export_type){
return Html::a('Open', '',
[
'data-url'=>'/model/payment/check-status/id/'. $model->id . '?exportType=' . $export_type ,
'class'=>'check-payment-status'
]);
}
],
],
]); ?>
<?php Pjax::end(); ?>
Here is my js:
<?php
$js = <<<JS
$(document).ready(function(){
function checkStatus() {
$(".check-payment-status").off().on("click", function(e){
e.preventDefault();
var url = $(this).attr("data-url");
$.pjax.defaults.timeout = false;
$.ajax({
url : url,
type : "post",
dataType: 'json',
success: function (response) {
// do something
}, error : function () {
// do nothing
}
});
});
}
checkStatus();
});
JS;
$this->registerJs($js);
I guess I need to use something like this, but still don't know how to implement it
$.each($('.check-payment-status'), function (i, el) {
//do something
});
So can I really do that? Calling the action automatically after the page load for each row?
All you need to do is to trigger the click event on the buttons.
$(document).ready(function() {
//bind the click handler
$('.btn').on('click', function(e) {
e.preventDefault();
console.log("Clicked " + $(this).text());
});
//click each button
$('.btn').each(function() {
$(this).trigger('click');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Link 1<br>
Link 2<br>
Link 3<br>
{!! Form::select('jobsList[]', $list_of_jobs, null, ['id' => 'job', 'class' => 'form-control' 'multiple', 'style' => 'width: 60%; margin-top: 10px;', 'disabled'=>'disabled']) !!}
I have this form and I am trying to load $list_of_jobs asynchronously compared to what I am doing. I am kind of confused with the way LaravelCollective Form works. Can anyone point out how I would pass that? I already have ajax call that goes and grabs the $list_of_jobs from the controller
//...
{!! Form::select('jobsList[]', [], null, ['id' => 'job', 'class' => 'form-control' 'multiple', 'style' => 'width: 60%; margin-top: 10px;', 'disabled'=>'disabled']) !!}
..//
Populating your select box using JQUERY, AJAX
<script>
$(document).ready(function() {
//Make an Ajax request to a Laravel route
//This will return the data that we can add to our Select element.
$.ajax({
url: 'YOUR URL GOES HERE',
type: 'get',
success: function(data){
//Log the data to the console so that
//you can get a better view of what the script is returning.
console.log(data);
$.each(data, function(key, value){
//Use the Option() constructor to create a new HTMLOptionElement.
var option = new Option(key, value);
//Convert the HTMLOptionElement into a JQuery object that can be used with the append method.
$(option).html(value);
//Append the option to our Select element.
$("#job").append(option);
});
}
});
});
</script>
data must be an array of objects [{}, {}, {}]
[
{'key' : 'foo', 'value' => 'bar'},
{'key' : 'kosksi', 'value' => 'makrouna'},
{'key' : 'lablebi', 'value' => 'kafteji'}
]
Update
If you want to set selected option(s) when Populating your select box :
You need to return an extra attribute selected : true|false in each object of data collection
[
{'key' : 'foo', 'value' : 'bar', 'selected' : false},
{'key' : 'kosksi', 'value' : 'makrouna', 'selected' : false},
{'key' : 'lablebi', 'value' : 'kafteji', 'selected' : true}
]
Then in success() ajax function callback
//...
$.each(data, function(key, elem){
//Use the Option() constructor to create a new HTMLOptionElement.
var option = new Option(elem.value, elem.key, false, elem.selected);
//Convert the HTMLOptionElement into a JQuery object that can be used with the append method.
$(option).html(elem.value);
//Append the option to our Select element.
$("#job").append(option);
});
//...
I am using Laravel Collective form. I want to use onclick analytic.js but the browser shows me an error. here is the code
<div class="field-name">
{{--<%= f.text_field :name, placeholder: 'your name', :onclick => "ga('send','event', 'form-lp-input', 'step3-name', '', 0);" %>--}}
{!!Form::text('name','yes',null,['placeholder'=>'yourname','onclick'=>'ga('send', 'event', 'form-lp-input', 'step2-zip',
'', 0);'])!!}
</div>
here is the output
There are two problems in your code:
Form::text() only uses 3 parameters, you are passing 4:
public static function text($name, $value = null, $options = array())
You have to escape your single-quoted javscript string or use double-quotes:
try this:
{!!Form::text('name', 'yes', ['placeholder' => 'yourname', 'onclick' => 'ga("send", "event", "form-lp-input", "step2-zip","", 0);'])!!}
I see I'm answering a bit late :) but still, maybe this solution will help someone...
To escape quotes you can use \Illuminate\Support\HtmlString class as following:
{!! Form::text('name', 'yes', ['placeholder' => 'yourname', 'onclick' => (new \Illuminate\Support\HtmlString("ga('send', 'event', 'form-lp-input', 'step2-zip', '', 0)"))]) !!}
I have problem with drupal 7 and form ajax callback.
I have simple form with form select item and when i choose something ajax callback show item with form radios. Its actually works, but I get only radios item title and description but no options to choose.
function my_test_form($form, &$form_state) {
$form['places'] = array(
'#type' => 'select',
'#title' => t('Select twitter trends location'),
'#options' => array('1' => 'item 1', '2' => 'item 2'),
'#default_value' => 1,
'#description' => t('Select description'),
'#ajax' => array(
'callback' => 'my_test_form_callback',
'wrapper' => '.form-item.form-type-select.form-item-places',
'method' => 'append',
'effect' => 'fade',
),
);
return $form;
}
function my_test_form_callback($form, &$form_state) {
$form['trends'] = array(
'#type' => 'radios',
'#title' => t('Select'),
'#options' => array(0 => t('Closed'), 1 => t('Active')),
'#default_value' => 0,
'#description' => t('Radios description.'),
);
return $form['trends'];
}
result of print $form['trends'] -> dpm(drupal_render($form['trends']));
<div class="form-item form-type-radios">
<label>Select trend </label>
<div class="form-radios"></div>
<div class="description">Radios description.</div>
</div>
I would be happy for every advice.
Thanks a lot.
The callback receives a built form. It's only responsible for returning the right part of the form.
function my_test_form_callback($form, &$form_state) {
return $form['trends'];
}
my_test_form is responsible for building the form for the first call and all the following AJAX calls. Simply put your condition inside this function.
in my project i am using the cgridview inside a modal window. now i am facing the problem that when i select the pagination the page get reloaded. how can i load the grid view with ajax pagination. my ui code id given below...
<div id="pick-category-modal" title="Pick Category" class="popupinfoholder2">
<div style="width:700px; height:auto;">
<?php
$widget = $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'response-grid',
'dataProvider' => $pickdataset->pickSection(),
'cssFile' => Yii::app()->baseUrl . '/media/css/gridview.css',
'summaryText' => '',
'ajaxUpdate'=>true,
'enablePagination' => true,
'template' => '{items}',
'pager' => array(
'class' => 'LinkPager',
'cssFile' => false,
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',
),
'columns' => array(
.....................
.....................
),));
?>
<div class="grid-view-footer">
<div class="paginationholder">
<div id="pagination">
<?php $widget->renderPager(); ?>
</div>
</div>
</div>
</div>
</div>
Just testing this myself a moment ago, it appears that the pager kicked out with renderPager() does not work with the AJAX setting. The CGridView JavaScript only binds the AJAX to pagers inside the <div> rendered by the widget (#response-grid here), so it does not find and use your additional pager.
I just use the default pager that the CGridView renders at the bottom, and that works fine.
You could override the CGridView JS to fix this, or list it as an enhancement on the Yii bug tracker: http://code.google.com/p/yii/issues/list