本文整理汇总了PHP中GFFormDisplay::add_init_script方法的典型用法代码示例。如果您正苦于以下问题:PHP GFFormDisplay::add_init_script方法的具体用法?PHP GFFormDisplay::add_init_script怎么用?PHP GFFormDisplay::add_init_script使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GFFormDisplay
的用法示例。
在下文中一共展示了GFFormDisplay::add_init_script方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_page_script
public static function add_page_script($form)
{
self::log_debug('Adding page script to ' . $form['id']);
$script = "(function(\$){" . "\$('#gform_" . $form['id'] . "').sisyphus();" . "})(jQuery);";
GFFormDisplay::add_init_script($form['id'], 'gravity-forms-js-validate', GFFormDisplay::ON_PAGE_RENDER, $script);
return $form;
}
示例2: register_init_scripts
public function register_init_scripts($form)
{
if (!$this->has_copy_cat_field($form)) {
return;
}
$copy_fields = $this->get_copy_cat_fields($form);
$enable_overwrite = gf_apply_filters('gpcc_overwrite_existing_values', $form['id'], false, $form);
$script = 'new gwCopyObj( ' . $form['id'] . ', ' . json_encode($copy_fields) . ', ' . ($enable_overwrite ? 'true' : 'false') . ' );';
GFFormDisplay::add_init_script($form['id'], 'gp-copy-cat', GFFormDisplay::ON_PAGE_RENDER, $script);
}
示例3: add_page_script
public static function add_page_script($form)
{
self::log_debug('Adding page script to ' . $form['id']);
$script = "(function(\$){" . "var container;" . "\$('.gfield_contains_required').each(function(i, e){" . "\$(e).find('input, select, textarea').attr('required', true);" . "});" . "\$('#gform_" . $form['id'] . "').validate({" . "debug: true," . "errorElement: 'div'," . "errorClass: 'gfield_error'," . "errorPlacement: function(error, element){" . "container = element.closest('.gfield');" . "},";
// Get messages for each input
$script .= "messages: {";
foreach ($form['fields'] as $field) {
$field_name = 'input_' . $field['id'];
// test
$field_errorMessage = "'" . $field['errorMessage'] . "',";
if ($field['errorMessage'] !== '') {
$script = $script . $field_name . ": " . $field_errorMessage;
}
}
$script .= "},";
$script .= "groups: getGroups()," . "focusCleanup: true," . "highlight: function(element, errorClass, validClass) {" . "\$(element).closest('.gfield').addClass(errorClass).removeClass(validClass);" . "}," . "unhighlight: function(element, errorClass, validClass) {" . "\$(element).closest('.gfield').removeClass(errorClass).addClass(validClass);" . "}," . "invalidHandler: function(event, validator) {" . "gf_submitting_" . $form['id'] . " = false;" . "}" . "});" . "})(jQuery);";
self::log_debug('Script is: ' . $script);
GFFormDisplay::add_init_script($form['id'], 'gf_js_validate', GFFormDisplay::ON_PAGE_RENDER, $script);
return $form;
}
开发者ID:cubetech,项目名称:wpplugin.gravity-forms-javascript-validation,代码行数:20,代码来源:gravity-forms-js-validate.php
示例4: register_form_init_scripts
/**
* Registers the script returned by get_form_inline_script_on_page_render() for display on the front-end.
*
* @param array $form The Form Object currently being processed.
*/
public function register_form_init_scripts($form)
{
GFFormDisplay::add_init_script($form['id'], $this->type . '_' . $this->id, GFFormDisplay::ON_PAGE_RENDER, $this->get_form_inline_script_on_page_render($form));
}
示例5: register_creditcard_token_script
/**
* Prepare Javascript for creating credit card tokens.
*
* @access public
*
* @param array $form
* @param array $field_values
* @param bool $is_ajax
*
* @return void
*/
public function register_creditcard_token_script($form, $field_values, $is_ajax)
{
if (!$this->enqueue_creditcard_token_script($form)) {
return;
}
/* Prepare GFToken object. */
$gftoken = array('callback' => 'GF_' . str_replace(' ', '', $this->_short_title), 'feeds' => $this->creditcard_token_info($form), 'formId' => rgar($form, 'id'), 'hasPages' => GFCommon::has_pages($form), 'pageCount' => GFFormDisplay::get_max_page_number($form), 'responseField' => '#gf_' . str_replace('gravityforms', '', $this->_slug) . '_response');
/* Get needed fields. */
$gftoken['fields'] = $this->get_creditcard_token_entry_fields($gftoken['feeds']);
$script = 'new GFToken( ' . json_encode($gftoken) . ' );';
GFFormDisplay::add_init_script($form['id'], 'GFToken', GFFormDisplay::ON_PAGE_RENDER, $script);
}
示例6: pre_render
function pre_render($form)
{
$script = '';
$output_script = false;
foreach ($form['fields'] as $field) {
$field_id = $field['id'];
$field_limits = $this->get_field_limits($field['id']);
if (!$field_limits || RGFormsModel::get_input_type($field) != 'checkbox' || !isset($field_limits['max'])) {
continue;
}
$output_script = true;
$max = $field_limits['max'];
$selectors = array();
foreach ($field_limits['field'] as $checkbox_field) {
$selectors[] = "#field_{$form['id']}_{$checkbox_field} .gfield_checkbox input:checkbox";
}
$script .= "jQuery(\"" . implode(', ', $selectors) . "\").checkboxLimit({$max});";
}
GFFormDisplay::add_init_script($form['id'], 'limit_checkboxes', GFFormDisplay::ON_PAGE_RENDER, $script);
if ($output_script) {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$.fn.checkboxLimit = function(n) {
var checkboxes = this;
this.toggleDisable = function() {
// if we have reached or exceeded the limit, disable all other checkboxes
if(this.filter(':checked').length >= n) {
var unchecked = this.not(':checked');
unchecked.prop('disabled', true);
}
// if we are below the limit, make sure all checkboxes are available
else {
this.prop('disabled', false);
}
}
// when form is rendered, toggle disable
checkboxes.bind('gform_post_render', checkboxes.toggleDisable());
// when checkbox is clicked, toggle disable
checkboxes.click(function(event) {
checkboxes.toggleDisable();
// if we are equal to or below the limit, the field should be checked
return checkboxes.filter(':checked').length <= n;
});
}
});
</script>
<?php
}
return $form;
}
示例7: register_init_scripts
public function register_init_scripts($form, $field_values, $is_ajax)
{
if (!$this->has_feed($form['id'])) {
return;
}
$cc_field = $this->get_credit_card_field($form);
$args = array('apiKey' => $this->get_publishable_api_key(), 'formId' => $form['id'], 'ccFieldId' => $cc_field['id'], 'ccPage' => rgar($cc_field, 'pageNumber'), 'isAjax' => $is_ajax, 'cardLabels' => $this->get_card_labels());
$script = 'new GFStripe( ' . json_encode($args) . ' );';
GFFormDisplay::add_init_script($form['id'], 'stripe', GFFormDisplay::ON_PAGE_RENDER, $script);
}
示例8: add_init_script
function add_init_script($return)
{
$start_field_format = false;
$end_field_format = false;
foreach ($this->form['fields'] as &$field) {
if ($field['id'] == $this->start_field_id) {
$start_field_format = $field['dateFormat'] ? $field['dateFormat'] : 'mdy';
}
if ($field['id'] == $this->end_field_id) {
$end_field_format = $field['dateFormat'] ? $field['dateFormat'] : 'mdy';
}
}
$script = " \n\t\t\n\t\tnew gwdc({\n formId: {$this->form['id']},\n startFieldId: {$this->start_field_id},\n startDateFormat: '{$start_field_format}',\n endFieldId: {$this->end_field_id},\n endDateFormat: '{$end_field_format}',\n countFieldId: {$this->count_field_id},\n countAdjust: {$this->count_adjust}\n });\n\t\t\t\n\t\t\t";
$slug = implode('_', array('gw_display_count', $this->start_field_id, $this->end_field_id, $this->count_field_id));
// GFFormDisplay::add_init_script( $this->form['id'], 'gw_display_count_' . $this->count_field_id, GFFormDisplay::ON_PAGE_RENDER, $script );
GFFormDisplay::add_init_script($this->form['id'], $slug, GFFormDisplay::ON_PAGE_RENDER, $script);
// remove filter so init script is not output on subsequent forms
remove_filter('gform_init_scripts_footer', array(&$this, 'add_init_script'));
return $return;
}
示例9: register_init_script
function register_init_script($form)
{
// remove this function from the filter otherwise it will be called for every other form on the page
remove_filter('gform_register_init_scripts', array($this, 'register_init_script'));
$args = array('formId' => $this->_args['form_id'], 'listFieldId' => $this->_args['list_field_id'], 'inputHtmlId' => $this->_args['input_html_id']);
$script = "new gwalfr(" . json_encode($args) . ");";
$key = implode('_', $args);
GFFormDisplay::add_init_script($form['id'], 'gwalfr_' . $key, GFFormDisplay::ON_PAGE_RENDER, $script);
}
示例10: initialise_form_edit
public static function initialise_form_edit()
{
/*
* If we aren't editing our form, don't do anything
*/
if (empty($_GET['action']) || empty($_GET['lid']) || !is_user_logged_in()) {
return false;
}
$lid = isset($_GET['lid']) ? (int) $_GET['lid'] : 0;
self::$lead = $lead = GFAPI::get_entry($lid);
self::$form = $form = GFAPI::get_form(self::$lead['form_id']);
if (!self::check_user_permission(self::$lead)) {
return false;
}
self::$allowed_edit = true;
if (!class_exists('GFFormDisplay')) {
require_once GFCommon::get_base_path() . "/form_display.php";
}
$field_values = RGForms::post("gform_field_values");
/*
* Include appropriate css/javascript here...
*/
GFFormDisplay::enqueue_form_scripts($form, false);
GFFormDisplay::add_init_script($form["id"], "conditional_logic", GFFormDisplay::ON_PAGE_RENDER, self::get_conditional_logic($form, $field_values));
GFFormDisplay::add_init_script($form["id"], "pricing", GFFormDisplay::ON_PAGE_RENDER, GFFormDisplay::get_pricing_init_script($form));
$chosen_script = GFFormDisplay::get_chosen_init_script($form);
GFFormDisplay::add_init_script($form["id"], "chosen", GFFormDisplay::ON_PAGE_RENDER, $chosen_script);
GFFormDisplay::add_init_script($form["id"], "chosen", GFFormDisplay::ON_CONDITIONAL_LOGIC, $chosen_script);
GFFormDisplay::add_init_script($form['id'], 'input_mask', GFFormDisplay::ON_PAGE_RENDER, GFFormDisplay::get_input_mask_init_script($form));
GFFormDisplay::add_init_script($form['id'], 'calculation', GFFormDisplay::ON_PAGE_RENDER, GFFormDisplay::get_calculations_init_script($form));
GFFormDisplay::add_init_script($form['id'], 'currency_format', GFFormDisplay::ON_PAGE_RENDER, GFFormDisplay::get_currency_format_init_script($form));
return true;
}
示例11: registerInitScripts
public function registerInitScripts($form, $field_values, $is_ajax)
{
if (!$this->has_feed($form['id'])) {
return;
}
$feeds = GFAPI::get_feeds(null, $form['id']);
$feed = $feeds[0];
$cc_field = $this->get_credit_card_field($form);
$args = array('apiKey' => $this->getPublicApiKey($feed), 'formId' => $form['id'], 'ccFieldId' => $cc_field['id'], 'ccPage' => rgar($cc_field, 'pageNumber'), 'isAjax' => $is_ajax);
$script = 'new SecureSubmit(' . json_encode($args) . ');';
GFFormDisplay::add_init_script($form['id'], 'securesubmit', GFFormDisplay::ON_PAGE_RENDER, $script);
}
示例12: get_field_input
public function get_field_input($form, $value = '', $entry = null)
{
if (is_admin()) {
return '';
} else {
$form_id = $form['id'];
$is_entry_detail = $this->is_entry_detail();
$is_form_editor = $this->is_form_editor();
$id = (int) $this->id;
$field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}";
$tabindex = $this->get_tabindex();
$repeater_id = $this->repeaterId;
$repeater_parem = $this->inputName;
$repeater_required = $this->repeaterRequiredChildren;
$repeater_children = $this->repeaterChildren;
$repeater_start = apply_filters('gf_repeater_start', $this->start, $form, $this);
$repeater_min = apply_filters('gf_repeater_min', $this->min, $form, $this);
$repeater_max = apply_filters('gf_repeater_max', $this->max, $form, $this);
$repeater_animations = apply_filters('gf_repeater_animations', $this->animations, $form, $this);
if (!empty($repeater_parem)) {
$repeater_parem_value = GFFormsModel::get_parameter_value($repeater_parem, $value, $this);
if (!empty($repeater_parem_value)) {
$repeater_start = $repeater_parem_value;
}
}
if (!empty($repeater_children)) {
$repeater_children_info = array();
$repeater_parems = GF_Field_Repeater::get_children_parem_values($form, $repeater_children);
foreach ($repeater_children as $repeater_child) {
$repeater_children_info[$repeater_child] = array();
$repeater_child_field_index = GF_Field_Repeater::get_field_index($form, 'id', $repeater_child);
if (!empty($repeater_required)) {
if (in_array($repeater_child, $repeater_required)) {
$repeater_children_info[$repeater_child]['required'] = true;
}
}
if (!empty($repeater_parems)) {
if (array_key_exists($repeater_child, $repeater_parems)) {
$repeater_children_info[$repeater_child]['prePopulate'] = $repeater_parems[$repeater_child];
}
}
if ($repeater_child_field_index !== false) {
$repeater_child_field = $form['fields'][$repeater_child_field_index];
if ($repeater_child_field['inputMask']) {
$repeater_children_info[$repeater_child]['inputMask'] = $repeater_child_field['inputMaskValue'];
} elseif ($repeater_child_field['type'] == 'phone' && ($repeater_child_field['phoneFormat'] = 'standard')) {
$repeater_children_info[$repeater_child]['inputMask'] = "(999) 999-9999";
}
if ($repeater_child_field['conditionalLogic']) {
$repeater_children_info[$repeater_child]['conditionalLogic'] = $repeater_child_field['conditionalLogic'];
}
if ($repeater_child_field['maxLength']) {
$repeater_children_info[$repeater_child]['maxLength'] = $repeater_child_field['maxLength'];
}
if ($repeater_child_field['enableEnhancedUI']) {
$repeater_children_info[$repeater_child]['enableEnhancedUI'] = $repeater_child_field['enableEnhancedUI'];
}
}
}
$repeater_children = $repeater_children_info;
}
$value = array();
$value['formId'] = $form_id;
if (!empty($repeater_start)) {
$value['start'] = $repeater_start;
}
if (!empty($repeater_min)) {
$value['min'] = $repeater_min;
}
if (!empty($repeater_max)) {
$value['max'] = $repeater_max;
}
if (!empty($repeater_children)) {
$value['children'] = $repeater_children;
}
$value = json_encode($value);
if (!empty($repeater_animations)) {
$animation_script = "var animations={" . $repeater_animations . "};jQuery.extend(true,gfRepeater_repeaters[" . $form_id . "][" . $repeater_id . "].settings.animations,animations);";
GFFormDisplay::add_init_script($form_id, 'repeater_animations', GFFormDisplay::ON_PAGE_RENDER, $animation_script);
}
return sprintf("<input name='input_%d' id='%s' type='hidden' class='gform_repeater' value='%s' %s />", $id, $field_id, $value, $tabindex);
}
}
示例13: filter_gform_register_init_scripts
public function filter_gform_register_init_scripts($form, $field_values, $is_ajax)
{
if ($this->has_enhanced_dropdown($form)) {
$chosen_script = $this->get_chosen_init_script($form);
GFFormDisplay::add_init_script($form['id'], 'workflow_assignee_chosen', GFFormDisplay::ON_PAGE_RENDER, $chosen_script);
GFFormDisplay::add_init_script($form['id'], 'workflow_assignee_chosen', GFFormDisplay::ON_CONDITIONAL_LOGIC, $chosen_script);
}
}
示例14: gform_addScript
function gform_addScript($form)
{
$script = '(function(){' . 'jQuery("input[type=radio][name=input_1]").change(function(){
if (jQuery(this).val().indexOf("Standard Presentation") > -1) {
//disable "45 minutes" option
jQuery("input[name=\'input_2.3\']").attr("disabled",true);
//if option is already checked, uncheck it
jQuery("input[name=\'input_2.3\']").attr("checked",false);
}else{
jQuery("input[name=\'input_2.3\']").attr("disabled",false);
}
});' . '})(jQuery);';
GFFormDisplay::add_init_script($form['id'], 'formScript', GFFormDisplay::ON_PAGE_RENDER, $script);
return $form;
}
示例15: register_init_scripts
/**
* Register Stripe script when displaying form.
*
* @param array $form Form object.
* @param array $field_values Current field values.
* @param bool $is_ajax If form is being submitted via AJAX.
*/
public function register_init_scripts($form, $field_values, $is_ajax)
{
// If form does not have a Stripe feed and does not have a credit card field, exit.
if (!$this->has_feed($form['id'])) {
return;
}
$cc_field = $this->get_credit_card_field($form);
if (!$cc_field) {
return;
}
// Prepare Stripe Javascript arguments.
$args = array('apiKey' => $this->get_publishable_api_key(), 'formId' => $form['id'], 'ccFieldId' => $cc_field->id, 'ccPage' => $cc_field->pageNumber, 'isAjax' => $is_ajax, 'cardLabels' => $this->get_card_labels());
// Initialize Stripe script.
$script = 'new GFStripe( ' . json_encode($args) . ' );';
// Add Stripe script to form scripts.
GFFormDisplay::add_init_script($form['id'], 'stripe', GFFormDisplay::ON_PAGE_RENDER, $script);
}