auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -1,2 +1,2 @@
/*! Do not edit, this file is generated automatically - 2024-03-18 16:03:44 EDT */
/*! Do not edit, this file is generated automatically - 2024-04-15 15:04:12 EDT */
window.$=window.$||jQuery.noConflict();var dtx={queue:[],init:function(){var e=$("input.dtx-pageload[data-dtx-value]");e.length&&(e.each(function(e,t){var r=$(t),a=r.attr("data-dtx-value"),o=decodeURIComponent(a).split(" ");if(o.length){var n=o[0],c={};if(1<o.length)for(var i=1;i<o.length;i++){var u=o[i].split("="),d;2===u.length&&(c[u[0]]=u[1].split("'").join(""))}var s="";switch(n){case"CF7_GET":s=dtx.get(c);break;case"CF7_referrer":s=dtx.referrer(c);break;case"CF7_URL":s=dtx.current_url(c);break;case"CF7_get_cookie":s=dtx.get_cookie(c);break;case"CF7_guid":s=dtx.guid();break;case"CF7_get_current_var":if(!dtx.validKey(c,"key")||"url"!=c.key)return;s=dtx.current_url(c);break;case"CF7_get_post_var":case"CF7_get_custom_field":case"CF7_get_taxonomy":case"CF7_get_attachment":case"CF7_bloginfo":case"CF7_get_theme_option":return;default:return void(n&&dtx.queue.push({value:a,multiline:r.is("textarea")}))}dtx.set(r,s)}}),dtx.queue.length)&&setTimeout(function(){$.ajax({type:"POST",url:dtx_obj.ajax_url,dataType:"json",data:{action:"wpcf7dtx",shortcodes:dtx.queue},cache:!1,error:function(e,t,r){},success:function(e,t,r){"object"==typeof e&&e.length&&$.each(e,function(e,t){var r=$('.wpcf7 form input.dtx-pageload[data-dtx-value="'+t.raw_value+'"]');r.length&&(r.addClass("dtx-ajax-loaded"),dtx.set(r,t.value))})}})},10)},validKey:function(e,t){return e.hasOwnProperty(t)&&"string"==typeof e[t]&&e[t].trim()},obfuscate:function(e,t){if(e=e.trim(),dtx.validKey(t,"obfuscate")&&t.obfuscate){for(var r="",a=0;a<e.length;a++)r+="&#"+e.codePointAt(a)+";";return r}return e},set:function(e,t){e.attr("value",t).addClass("dtx-loaded").trigger("dtx_init")},get:function(e){if(dtx.validKey(e,"key")){var t=window.location.search;if(t)return t=new URLSearchParams(t),dtx.obfuscate(t.get(e.key).trim(),e)}return""},referrer:function(e){return dtx.obfuscate(document.referrer,e)},current_url:function(e){if(!e.hasOwnProperty("part"))return dtx.obfuscate(window.location.href,e);var t;if(["scheme","host","port","path","query","fragment"].includes(e.part))switch(e.part){case"scheme":return dtx.obfuscate(window.location.protocol.replace(":",""),e);case"host":return dtx.obfuscate(window.location.host,e);case"port":return dtx.obfuscate(window.location.port,e);case"path":return dtx.obfuscate(window.location.pathname,e);case"query":return dtx.obfuscate(window.location.search.replace("?",""),e);case"fragment":return dtx.obfuscate(window.location.hash.replace("#",""),e)}return""},get_cookie:function(e){var t;return e.hasOwnProperty("key")&&"string"==typeof e.key&&""!=e.key.trim()&&(t=document.cookie.match("(^|;) ?"+e.key.trim()+"=([^;]*)(;|$)"))?dtx.obfuscate(t[2],e):""},guid:function(){var r,a;return(void 0!==window.crypto&&void 0!==window.crypto.getRandomValues?([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)):(r=(new Date).getTime(),a="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0,"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random();return 0<r?(t=(r+t)%16|0,r=Math.floor(r/16)):(t=(a+t)%16|0,a=Math.floor(a/16)),("x"===e?t:3&t|8).toString(16).toUpperCase()}))).toUpperCase()}};$(document).ready(dtx.init);

View File

@@ -6,6 +6,14 @@
window.wpcf7dtx = window.wpcf7dtx || {};
wpcf7dtx.taggen = {};
$('input.dtx-insert-tag').click(function() {
var $form = $(this).closest('form.tag-generator-panel');
var tag = $form.find('.insert-box .tag').val();
wpcf7.taggen.insert(tag);
tb_remove(); // close thickbox
return false;
});
wpcf7dtx.taggen.escapeRegExp = function(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
};
@@ -19,10 +27,59 @@
return input;
};
// Overwrite update function to allow the textarea display for advanced tags
wpcf7.taggen.update = function($form) {
var id = $form.attr('data-id');
var name = '';
var name_fields = $form.find('input[name="name"]');
if (name_fields.length) {
name = name_fields.val();
if ('' === name) {
name = id + '-' + Math.floor(Math.random() * 1000);
name_fields.val(name);
}
}
if ($.isFunction(wpcf7.taggen.update[id])) {
return wpcf7.taggen.update[id].call(this, $form);
}
let $display = $form.find('.insert-box .tag');
// if (!$display.length) {
// $display = $form.find('textarea.tag');
// }
$display.each(function() {
var tag_type = $(this).attr('name');
if ($form.find(':input[name="tagtype"]').length) {
tag_type = $form.find(':input[name="tagtype"]').val();
}
if ($form.find(':input[name="required"]').is(':checked')) {
tag_type += '*';
}
var components = wpcf7.taggen.compose(tag_type, $form);
$(this).val(components);
});
$form.find('span.mail-tag').text('[' + name + ']');
$form.find('input.mail-tag').each(function() {
$(this).val('[' + name + ']');
});
};
wpcf7dtx.taggen.updateOption = function(e) {
var $this = $(e.currentTarget),
value = encodeURIComponent(wpcf7dtx.taggen.replaceAll($this.val(), "'", '&#39;'));
$this.siblings('input[type="hidden"].option').val(value);
value = encodeURIComponent(wpcf7dtx.taggen.replaceAll($this.val(), "'", '&#39;')),
$option = $this.siblings('input[type="hidden"].option');
$option.val(value);
if (e.type != 'change') {
// DTX only listens for "change" so force the tag to rebuild for our other listeners
$option.trigger('change');
}
};
$(function() {
@@ -31,8 +88,13 @@
var $btn = $(this),
name = $btn.text();
$btn.addClass('dtx-form-tag');
if (name == 'dynamic drop-down menu' || name == 'dynamic checkboxes' || name == 'dynamic radio buttons') {
$btn.attr('href', $btn.attr('href').replace('height=500', 'height=750'));
if (
name.indexOf('dynamic ') === 0 && // Set size of tag generator to be larger for dynamic fields
name.indexOf('hidden') < 0 && // Except for this one because it doesn't have a lot of options
name.indexOf('label') < 0 && // Except for this one because it doesn't have a lot of options
name.indexOf('submit') < 0 // Except for this one because it doesn't have a lot of options
) {
$btn.attr('href', $btn.attr('href').replace('height=500', 'height=785'));
}
});
});

View File

@@ -1,2 +1,2 @@
/*! Do not edit, this file is generated automatically - 2024-03-18 16:03:44 EDT */
!function(n){"use strict";"undefined"!=typeof wpcf7&&null!==wpcf7&&(window.wpcf7dtx=window.wpcf7dtx||{},wpcf7dtx.taggen={},wpcf7dtx.taggen.escapeRegExp=function(e){return e.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")},wpcf7dtx.taggen.replaceAll=function(e,t,n,a){var c;return null!=e&&"string"==typeof e&&""!==e.trim()&&-1<e.indexOf(t)?(c=new RegExp(wpcf7dtx.taggen.escapeRegExp(t),"g"),a&&(c=new RegExp(t,"g")),e.replace(c,n)):e},wpcf7dtx.taggen.updateOption=function(e){var e=n(e.currentTarget),t=encodeURIComponent(wpcf7dtx.taggen.replaceAll(e.val(),"'","&#39;"));e.siblings('input[type="hidden"].option').val(t)},n(function(){n("form.tag-generator-panel .dtx-option").on("change keyup click",wpcf7dtx.taggen.updateOption),n('.contact-form-editor-panel #tag-generator-list a.thickbox.button[href*="inlineId=tag-generator-panel-dynamic_"]').each(function(){var e=n(this),t=e.text();e.addClass("dtx-form-tag"),"dynamic drop-down menu"!=t&&"dynamic checkboxes"!=t&&"dynamic radio buttons"!=t||e.attr("href",e.attr("href").replace("height=500","height=750"))})}))}(jQuery);
/*! Do not edit, this file is generated automatically - 2024-04-15 15:04:12 EDT */
!function(g){"use strict";"undefined"!=typeof wpcf7&&null!==wpcf7&&(window.wpcf7dtx=window.wpcf7dtx||{},wpcf7dtx.taggen={},g("input.dtx-insert-tag").click(function(){var t,e=g(this).closest("form.tag-generator-panel").find(".insert-box .tag").val();return wpcf7.taggen.insert(e),tb_remove(),!1}),wpcf7dtx.taggen.escapeRegExp=function(t){return t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")},wpcf7dtx.taggen.replaceAll=function(t,e,n,a){var i;return null!=t&&"string"==typeof t&&""!==t.trim()&&-1<t.indexOf(e)?(i=new RegExp(wpcf7dtx.taggen.escapeRegExp(e),"g"),a&&(i=new RegExp(e,"g")),t.replace(i,n)):t},wpcf7.taggen.update=function(e){var t=e.attr("data-id"),n="",a=e.find('input[name="name"]'),i;if(a.length&&""===(n=a.val())&&(n=t+"-"+Math.floor(1e3*Math.random()),a.val(n)),g.isFunction(wpcf7.taggen.update[t]))return wpcf7.taggen.update[t].call(this,e);e.find(".insert-box .tag").each(function(){var t=g(this).attr("name"),t=(e.find(':input[name="tagtype"]').length&&(t=e.find(':input[name="tagtype"]').val()),e.find(':input[name="required"]').is(":checked")&&(t+="*"),wpcf7.taggen.compose(t,e));g(this).val(t)}),e.find("span.mail-tag").text("["+n+"]"),e.find("input.mail-tag").each(function(){g(this).val("["+n+"]")})},wpcf7dtx.taggen.updateOption=function(t){var e=g(t.currentTarget),n=encodeURIComponent(wpcf7dtx.taggen.replaceAll(e.val(),"'","&#39;")),e=e.siblings('input[type="hidden"].option');e.val(n),"change"!=t.type&&e.trigger("change")},g(function(){g("form.tag-generator-panel .dtx-option").on("change keyup click",wpcf7dtx.taggen.updateOption),g('.contact-form-editor-panel #tag-generator-list a.thickbox.button[href*="inlineId=tag-generator-panel-dynamic_"]').each(function(){var t=g(this),e=t.text();t.addClass("dtx-form-tag"),0===e.indexOf("dynamic ")&&e.indexOf("hidden")<0&&e.indexOf("label")<0&&e.indexOf("submit")<0&&t.attr("href",t.attr("href").replace("height=500","height=785"))})}))}(jQuery);

View File

@@ -1,7 +1,6 @@
.tag-generator-panel[data-id^="dynamic_select"],
.tag-generator-panel[data-id^="dynamic_checkbox"],
.tag-generator-panel[data-id^="dynamic_radio"] {
height: 740px;
.tag-generator-panel[data-id^="dynamic_"]:not([data-id*="hidden"]):not([data-id*="label"]):not([data-id*="submit"]) {
/* Set size of tag generator to be larger for dynamic fields, except for these because they don't have a lot of options */
height: 775px;
}
#tag-generator-list a.button.dtx-form-tag {
@@ -43,4 +42,26 @@
.tag-generator-panel .control-box textarea {
height: 3.5em;
}
.tag-generator-panel table.form-table td .wpcf7dtx-mini-att,
.tag-generator-panel table.form-table td .wpcf7dtx-mini-att label,
.tag-generator-panel table.form-table td .wpcf7dtx-mini-att input[type="text"] {
vertical-align: middle;
}
.tag-generator-panel .insert-box textarea.tag {
border-radius: 4px;
border: 1px solid #8c8f94;
color: #2c3338;
/* padding: 0 8px; */
/* line-height: 2; */
min-height: 30px;
width: 500px;
float: left;
background-color: transparent;
box-shadow: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}

View File

@@ -1 +1 @@
.tag-generator-panel[data-id^=dynamic_checkbox],.tag-generator-panel[data-id^=dynamic_radio],.tag-generator-panel[data-id^=dynamic_select]{height:740px}#tag-generator-list a.button.dtx-form-tag{border-color:#765cb9;color:#765cb9}.tag-generator-panel table.form-table th{width:130px}.tag-generator-panel table.form-table td small{display:block;margin-top:.25em}.tag-generator-panel .control-box input.multiline,.tag-generator-panel .control-box input.oneline,.tag-generator-panel .control-box textarea{width:100%}.tag-generator-panel .control-box input.multiline,.tag-generator-panel .control-box input[list],.tag-generator-panel .control-box textarea{height:30px;min-height:30px}.tag-generator-panel .control-box input.multiline{display:inline-block;resize:vertical;overflow-x:hidden;overflow-y:scroll}.tag-generator-panel .control-box textarea{height:3.5em}
.tag-generator-panel[data-id^=dynamic_]:not([data-id*=hidden]):not([data-id*=label]):not([data-id*=submit]){height:775px}#tag-generator-list a.button.dtx-form-tag{border-color:#765cb9;color:#765cb9}.tag-generator-panel table.form-table th{width:130px}.tag-generator-panel table.form-table td small{display:block;margin-top:.25em}.tag-generator-panel .control-box input.multiline,.tag-generator-panel .control-box input.oneline,.tag-generator-panel .control-box textarea{width:100%}.tag-generator-panel .control-box input.multiline,.tag-generator-panel .control-box input[list],.tag-generator-panel .control-box textarea{height:30px;min-height:30px}.tag-generator-panel .control-box input.multiline{display:inline-block;resize:vertical;overflow-x:hidden;overflow-y:scroll}.tag-generator-panel .control-box textarea{height:3.5em}.tag-generator-panel table.form-table td .wpcf7dtx-mini-att,.tag-generator-panel table.form-table td .wpcf7dtx-mini-att input[type=text],.tag-generator-panel table.form-table td .wpcf7dtx-mini-att label{vertical-align:middle}.tag-generator-panel .insert-box textarea.tag{border-radius:4px;border:1px solid #8c8f94;color:#2c3338;min-height:30px;width:500px;float:left;background-color:transparent;box-shadow:none;-webkit-appearance:none;-moz-appearance:none;appearance:none}

View File

@@ -1,5 +1,24 @@
== Changelog ==
= 4.4.2 =
* Fix: Addressed PHP warning for undefined variable $default_placeholder introduced in version 4.4.0, [see support thread](https://wordpress.org/support/topic/php-warning-undefined-variable-default_placeholder/)
* Minor: Create preview link using WordPress Playground, [check it out](https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/?preview=1)
= 4.4.1 =
* Fix: Addressed PHP warnings for undefined array keys introduced in version 4.4.0, [see support thread](https://wordpress.org/support/topic/tons-of-errors-in-error_log/)
= 4.4.0 =
* Update: Added *Contact Form 7* (CF7) as a requirement as introduced in WordPress version 6.5. This plugin cannot be activated until CF7 is installed and activated.
* Feature: introduced `dynamic_label` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-label/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
* Feature: updated the following attributes to be dynamic: `autocapitalize`, `autocomplete`, `autofocus`, `cols`, `disabled`, `list`, `max`, `maxlength`, `min`, `minlength`, `pattern`, `readonly`, `size`, and `step`. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/dynamic-attributes/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
* Update: Updated the form tag generator for checkboxes and radio buttons to include documentation for the `default` attribute.
* Update: Updated the form tag generator with fields for `min`, `max`, `step`, `minlength`, `maxlength`, and `autocomplete` for appropriate form tags. The `autocomplete` and `autocapitalize` are text fields that uses a `datalist` because I always forget those things...
* Update: Increased the tag generator size to accommodate the new attributes.
* Update: Some form tag generators display the generated form tag in a `textarea` to accommodate lengthy generated form tags.
= 4.3.1 =
* Fix: Resolved the PHP warning regarding `Undefined array key "value" in /.../contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension.php on line 391`, [see support thread](https://wordpress.org/support/topic/undefined-array-key-value-2/).

View File

@@ -3,7 +3,8 @@
/**
* Plugin Name: Contact Form 7 - Dynamic Text Extension
* Description: Extends Contact Form 7 by adding dynamic form fields that accepts shortcodes to prepopulate form fields with default values and dynamic placeholders.
* Version: 4.3.1
* Version: 4.4.2
* Text Domain: contact-form-7-dynamic-text-extension
* Author: AuRise Creative, SevenSpark
* Author URI: https://aurisecreative.com
* Plugin URI: https://aurisecreative.com/products/wordpress-plugin/contact-form-7-dynamic-text-extension/
@@ -11,7 +12,7 @@
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Requires at least: 5.5
* Requires PHP: 7.4
* Text Domain: contact-form-7-dynamic-text-extension
* Requires Plugins: contact-form-7
*
* @copyright Copyright (c) 2010-2024 Chris Mavricos, SevenSpark <https://sevenspark.com>
* @copyright Copyright (c) 2022-2024 Tessa Watkins, AuRise Creative <https://aurisecreative.com>
@@ -31,7 +32,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define('WPCF7DTX_VERSION', '4.3.1'); // Define current version of DTX
define('WPCF7DTX_VERSION', '4.4.2'); // Define current version of DTX
define('WPCF7DTX_MINVERSION', '5.7'); // The minimum version of CF7 required to use mail validator
defined('WPCF7DTX_DIR') || define('WPCF7DTX_DIR', __DIR__); // Define root directory
defined('WPCF7DTX_FILE') || define('WPCF7DTX_FILE', __FILE__); // Define root file
@@ -162,6 +163,11 @@ function wpcf7dtx_config()
'title' => __('dynamic submit', 'contact-form-7-dynamic-text-extension'), //title
'options' => array(),
'description' => __('a submit button', 'contact-form-7-dynamic-text-extension')
),
'dynamic_label' => array(
'title' => __('dynamic label', 'contact-form-7-dynamic-text-extension'), //title
'options' => array(),
'description' => __('a label element', 'contact-form-7-dynamic-text-extension')
)
);
}
@@ -195,6 +201,10 @@ function wpcf7dtx_add_shortcodes()
$callback = 'wpcf7dtx_button_shortcode_handler';
$features['name-attr'] = false;
break;
case 'label':
$callback = 'wpcf7dtx_label_shortcode_handler';
$features['name-attr'] = false;
break;
default:
break;
}
@@ -278,21 +288,6 @@ function wpcf7dtx_shortcode_handler($tag)
} else {
$atts['aria-invalid'] = 'false';
}
if ($tag->has_option('readonly')) {
$atts['readonly'] = 'readonly';
}
// Dynamically determine disabled attribute, remove if invalid
$atts['disabled'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('disabled', '', true)), ENT_QUOTES));
if ($atts['disabled'] != 'disabled') {
unset($atts['disabled']);
}
// Dynamically determine autofocus attribute, remove if invalid
$atts['autofocus'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('autofocus', '', true)), ENT_QUOTES));
if ($atts['autofocus'] != 'autofocus') {
unset($atts['autofocus']);
}
// Add required attribute to applicable input types
if ($tag->is_required() && !in_array($atts['type'], array('hidden', 'quiz'))) {
@@ -300,6 +295,30 @@ function wpcf7dtx_shortcode_handler($tag)
$atts['required'] = 'required';
}
/**
* Attributes for all fields
*
* Any attributes that are not allowed on specific elements will be stripped during escaping.
* See the `wpcf7dtx_get_allowed_field_properties()` for details.
*/
$dynamic_atts = array('autofocus', 'disabled', 'readonly');
foreach ($dynamic_atts as $dynamic_att) {
// Don't override existing attributes
if (!array_key_exists($dynamic_att, $atts) && $tag->has_option($dynamic_att)) {
switch ($dynamic_att) {
default:
$atts[$dynamic_att] = wpcf7dtx_get_dynamic(false, $tag, 'text', $dynamic_att); // Get dynamic attribute
if ($atts[$dynamic_att] === '') {
$atts[$dynamic_att] = $dynamic_att; // Empty values are valid since boolean values just need to exist
}
if ($atts[$dynamic_att] !== $dynamic_att) {
unset($atts[$dynamic_att]); // Remove attribute if it doesn't equal it's own name
}
break;
}
}
}
// Evaluate the dynamic value
$sanitize_type = $atts['type'] == 'textarea' ? $atts['type'] : 'auto';
$value = wpcf7dtx_get_dynamic(false, $tag, $sanitize_type);
@@ -363,38 +382,107 @@ function wpcf7dtx_shortcode_handler($tag)
$atts['placeholder'] = wpcf7dtx_array_has_key('placeholder', $atts, __('&#8212;Please choose an option&#8212;', 'contact-form-7-dynamic-text-extension'));
}
if ($atts['type'] == 'select') {
$atts['size'] = $tag->get_size_option('1');
$atts['size'] = wpcf7dtx_get_dynamic(false, $tag, 'text', 'size'); // Get dynamic attribute
if ($atts['size'] === '') {
$atts['size'] = $tag->get_size_option('1'); // Set default value
}
}
} else {
/**
* Configuration for text-based fields
* Attributes for text-based fields
*
* Any attributes that are not allowed on specific elements will be stripped during escaping.
* See the `wpcf7dtx_get_allowed_field_properties()` for details.
*/
$atts['size'] = $tag->get_size_option('40');
$atts['list'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('list', '', true)), ENT_QUOTES));
$atts['autocapitalize'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('autocapitalize', '', true)), ENT_QUOTES));
$atts['pattern'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('pattern', '', true)), ENT_QUOTES));
$atts['min'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('min', '', true)), ENT_QUOTES));
$atts['max'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('max', '', true)), ENT_QUOTES));
$atts['step'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('step', '', true)), ENT_QUOTES));
$dynamic_atts = array('autocapitalize', 'autocomplete', 'cols', 'list', 'max', 'maxlength', 'min', 'minlength', 'pattern', 'rows', 'size', 'step');
foreach ($dynamic_atts as $dynamic_att) {
// Don't override existing attributes
if (!array_key_exists($dynamic_att, $atts) && $tag->has_option($dynamic_att)) {
$atts[$dynamic_att] = wpcf7dtx_get_dynamic(false, $tag, 'text', $dynamic_att); // Get dynamic attribute
switch ($dynamic_att) {
case 'autocapitalize':
if (!in_array($atts[$dynamic_att], array('none', 'off', 'on', 'sentences', 'words', 'characters'))) {
unset($atts[$dynamic_att]); // Remove if invalid
}
break;
case 'autocomplete':
// Autocomplete attribute
if ($atts['type'] == 'hidden') {
$atts['autocomplete'] = 'off'; // Always disable for hidden fields
} else {
// Disable autocomplete for this field if a value has been specified
$atts['autocomplete'] = $atts['value'] ? 'off' : $atts['autocomplete']; // Get dynamic attribute // Get dynamic attribute
}
break;
case 'maxlength':
if ($atts[$dynamic_att] === '' || !is_numeric($atts[$dynamic_att])) {
$atts[$dynamic_att] = $tag->get_maxlength_option(); // Set default if empty or invalid
}
break;
case 'minlength':
if ($atts[$dynamic_att] === '' || !is_numeric($atts[$dynamic_att])) {
$atts[$dynamic_att] = $tag->get_minlength_option(); // Set default if empty or invalid
}
break;
case 'cols':
if ($atts[$dynamic_att] === '' || !is_numeric($atts[$dynamic_att])) {
$atts[$dynamic_att] = $tag->get_cols_option('40'); // Set default if empty or invalid
}
break;
case 'rows':
if ($atts[$dynamic_att] === '' || !is_numeric($atts[$dynamic_att])) {
$atts[$dynamic_att] = $tag->get_rows_option('10'); // Set default if empty or invalid
}
break;
case 'size':
if ($atts[$dynamic_att] === '' || !is_numeric($atts[$dynamic_att])) {
$atts[$dynamic_att] = $tag->get_size_option('40'); // Set default if empty or invalid
}
break;
case 'wrap':
if (!in_array($atts[$dynamic_att], array('hard', 'soft'))) {
unset($atts[$dynamic_att]); // Remove if invalid
}
break;
default:
if ($atts[$dynamic_att] === '') {
unset($atts[$dynamic_att]); // Remove attribute if empty
}
break;
}
}
}
// Min and Max length attributes
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['minlength'] = $tag->get_minlength_option();
if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
// Validate Min and Max length attributes (should always be numeric)
if (array_key_exists('maxlength', $atts) && $atts['maxlength'] && array_key_exists('minlength', $atts) && $atts['minlength'] && intval($atts['maxlength']) < intval($atts['minlength'])) {
unset($atts['maxlength'], $atts['minlength']);
}
// Autocomplete attribute
if ($atts['type'] == 'hidden') {
$atts['autocomplete'] = 'off'; // Always disable for hidden fields
} else {
// Disable autocomplete for this field if a dynamic value has been specified
$atts['autocomplete'] = $atts['value'] ? 'off' : $tag->get_option('autocomplete', '[-0-9a-zA-Z]+', true);
/**
* The `maxlength` attribute must be an integer with a value of 0 or higher
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/maxlength
*/
if (array_key_exists('maxlength', $atts) && (!is_numeric($atts['maxlength']) || intval($atts['maxlength']) < 0)) {
unset($atts['maxlength']);
}
/**
* The `minlength` attribute must be an integer with a value of 0 or higher
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/minlength
*/
if (array_key_exists('minlength', $atts) && (!is_numeric($atts['minlength']) || intval($atts['minlength']) < 0)) {
unset($atts['minlength']);
}
}
// Validate Min and Max attributes if numeric
if (array_key_exists('max', $atts) && array_key_exists('min', $atts) && is_numeric($atts['max']) && is_numeric($atts['min']) && floatval($atts['max']) < floatval($atts['min'])) {
unset($atts['max'], $atts['min']);
}
// Client-side validation by type
switch ($atts['type']) {
case 'range':
// Client-side validation by type
$atts['class'][] = 'wpcf7-validates-as-number';
break;
case 'date':
@@ -402,18 +490,8 @@ function wpcf7dtx_shortcode_handler($tag)
case 'email':
case 'url':
case 'tel':
// Client-side validation by type
$atts['class'][] = sanitize_html_class('wpcf7-validates-as-' . $atts['type']);
break;
case 'textarea':
// Attributes unique to textareas
$atts['cols'] = $tag->get_cols_option('40');
$atts['rows'] = $tag->get_rows_option('10');
$atts['wrap'] = $tag->get_option('wrap', '', true);
if (!in_array($atts['wrap'], array('hard', 'soft'))) {
unset($atts['wrap']);
}
break;
}
}
@@ -538,6 +616,51 @@ function wpcf7dtx_button_shortcode_handler($tag)
);
}
/**
* Form Tag Handler for Dynamic Label
*
* @param WPCF7_FormTag $tag Current Contact Form 7 tag object
*
* @return string HTML output of the shortcode
*/
function wpcf7dtx_label_shortcode_handler($tag)
{
$atts = array();
$atts['id'] = strval($tag->get_id_option());
$atts['class'] = wpcf7_form_controls_class('wpcf7dtx wpcf7dtx-label');
$atts['for'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('for', '', true)), ENT_QUOTES)); // Get dynamic attribute
// Page load attribute
if ($tag->has_option('dtx_pageload') && is_array($tag->raw_values) && count($tag->raw_values)) {
$atts['data-dtx-value'] = rawurlencode(sanitize_text_field($tag->raw_values[0]));
$atts['class'] .= ' dtx-pageload';
if (wp_style_is('wpcf7dtx', 'registered') && !wp_script_is('wpcf7dtx', 'queue')) {
// If already registered, just enqueue it
wp_enqueue_script('wpcf7dtx');
} elseif (!wp_style_is('wpcf7dtx', 'registered')) {
// If not registered, do that first, then enqueue it
wpcf7dtx_enqueue_frontend_assets();
wp_enqueue_script('wpcf7dtx');
}
}
// Wrap up class attribute
$atts['class'] = $tag->get_class_option($atts['class']);
// Output the form field HTML
return wp_kses(
sprintf(
'<label %s>%s</label>',
wpcf7dtx_format_atts($atts),
wpcf7dtx_get_dynamic(false, $tag) // Evaluate the dynamic label text
),
array_merge(
wp_kses_allowed_html('data'), // Get allowed HTML for inline data
array('label' => wpcf7dtx_get_allowed_field_properties('label')) // Include our label field
)
);
}
/**
* AJAX Request Handler for After Page Loading
*

View File

@@ -109,7 +109,7 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
);
// Input field - Required checkbox (not available for some fields)
if (!in_array($input_type, array('hidden', 'quiz', 'submit', 'reset'))) {
if (!in_array($input_type, array('hidden', 'quiz', 'submit', 'reset', 'label'))) {
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
esc_attr($options['content'] . '-required'), // field id
@@ -124,7 +124,7 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
}
// Input field - Field Name (not available for some fields)
if (!in_array($input_type, array('submit', 'reset'))) {
if (!in_array($input_type, array('submit', 'reset', 'label'))) {
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s /></td></tr>',
esc_attr($options['content'] . '-name'), // field id
@@ -184,7 +184,29 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
esc_html__('View DTX shortcode syntax documentation', 'contact-form-7-dynamic-text-extension') // Link label
);
if ($input_type == 'select') {
if ($input_type == 'label') {
$placeholder_description = __('The id attribute of the element this label is for.', 'contact-form-7-dynamic-text-extension');
$placeholder_description .= __('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension');
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s /><input %s /><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/dynamic-attributes/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
esc_attr($options['content'] . '-for'), // field id
esc_html__('For attribute'), // field label
wpcf7_format_atts(array(
'type' => 'hidden',
'name' => 'for',
'class' => 'option'
)),
wpcf7_format_atts(array(
'name' => 'dtx-for',
'id' => $options['content'] . '-for', // field id
'class' => 'multiline dtx-option'
)),
esc_html($placeholder_description), // Small note below input
esc_attr($utm_source), //UTM source
esc_attr($type), //UTM content
esc_html__('View documentation for Dynamic Attributes', 'contact-form-7-dynamic-text-extension') //Link label
);
} elseif ($input_type == 'select') {
// Input field - Multiple selections checkbox
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
@@ -215,7 +237,7 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
}
// Input field - Dynamic placeholder (not available for some fields)
if (!in_array($input_type, array('hidden', 'radio', 'checkbox', 'quiz', 'submit', 'reset'))) {
if (!in_array($input_type, array('hidden', 'radio', 'checkbox', 'range', 'quiz', 'submit', 'reset', 'label'))) {
$placeholder_description = '';
if (in_array($input_type, array('select', 'checkbox', 'radio'))) {
$placeholder_label = __('First Option Label', 'contact-form-7-dynamic-text-extension');
@@ -335,14 +357,14 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
}
}
// Input field - Dynamic default value (not available for some fields)
if (in_array($input_type, array('select'))) {
// Input field - Dynamic default value (only available for selection-based fields)
if (in_array($input_type, array('select', 'checkbox', 'radio'))) {
$default_input_type = '<input %s />';
$default_placeholder = '';
if ($input_type == 'checkbox') {
$default_input_type = '<textarea %s></textarea>';
$default_description = __('Optionally define the default on/off status of the checkboxes by putting a 1 (checked) or 0 (not checked) on each line that corresponds with the options.', 'contact-form-7-dynamic-text-extension') . ' ';
$default_placeholder = '0' . PHP_EOL . '1';
//$default_input_type = '<textarea %s></textarea>';
$default_description = __('Optionally define which checkboxes are checked by default by defining the checked values using an underscore (_) delimited list.', 'contact-form-7-dynamic-text-extension') . ' ';
$default_placeholder = 'hello-world_Foo';
} else {
$default_description = __('Optionally define the option that is selected by default. This can be different than the first [blank] option. If options use key/value pairs, only define the key here.', 'contact-form-7-dynamic-text-extension') . ' ';
}
@@ -370,6 +392,75 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
);
}
// Input field - Range attributes (only available for numeric and date fields)
if (in_array($input_type, array('number', 'range', 'date'))) {
$default_input_type = 'number';
$default_placeholder = 'Foo';
$step_option = '';
if ($input_type == 'date') {
$default_input_type = 'date';
$default_description = __('Optionally define the minimum and/or maximum date values.', 'contact-form-7-dynamic-text-extension') . ' ';
$default_placeholder = 'hello-world_Foo';
} else {
$step_option = sprintf(
'&nbsp;<span class="wpcf7dtx-mini-att"><label for="%s">%s</label> <input %s /><input %s /></span>',
esc_attr($options['content'] . '-step'),
esc_html__('Step', 'contact-form-7-dynamic-text-extension'),
wpcf7_format_atts(array(
'type' => 'hidden',
'name' => 'step',
'class' => 'option'
)),
wpcf7_format_atts(array(
'type' => 'text',
'name' => 'dtx-step',
'id' => $options['content'] . '-step',
'class' => 'dtx-option',
'size' => 7
))
);
$default_description = __('Optionally define the minimum, maximum, and/or step values.', 'contact-form-7-dynamic-text-extension') . ' ';
}
$default_description .= __('Each can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension');
printf(
'<tr><th scope="row"><label>%s</label></th><td><span class="wpcf7dtx-mini-att"><label for="%s">%s</label> <input %s /><input %s /></span> - <span class="wpcf7dtx-mini-att"><label for="%s">%s</label> <input %s /><input %s /></span>%s<br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/dynamic-attributes/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
esc_html__('Range', 'contact-form-7-dynamic-text-extension'), // field label
esc_attr($options['content'] . '-min'),
esc_html__('Min', 'contact-form-7-dynamic-text-extension'),
wpcf7_format_atts(array(
'type' => 'hidden',
'name' => 'min',
'class' => 'option'
)),
wpcf7_format_atts(array(
'type' => 'text',
'name' => 'dtx-min',
'id' => $options['content'] . '-min',
'class' => 'dtx-option',
'size' => 7
)),
esc_attr($options['content'] . '-max'),
esc_html__('Max', 'contact-form-7-dynamic-text-extension'),
wpcf7_format_atts(array(
'type' => 'hidden',
'name' => 'max',
'class' => 'option'
)),
wpcf7_format_atts(array(
'type' => 'text',
'name' => 'dtx-max',
'id' => $options['content'] . '-max',
'class' => 'dtx-option',
'size' => 7
)),
$step_option, // Optional "step" option for numbers and ranges
esc_html($default_description), // Small note below input
esc_attr($utm_source), //UTM source
esc_attr($type), //UTM content
esc_html__('View documentation for Dynamic Attributes', 'contact-form-7-dynamic-text-extension') //Link label
);
}
//Input field - ID attribute
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s /></td></tr>',
@@ -396,8 +487,152 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
))
);
// Input field - Maxlenth & Minlength attributes (only available for visible text fields)
if (!in_array($input_type, array('hidden', 'quiz', 'submit', 'reset', 'label', 'number', 'range', 'date', 'select', 'checkbox', 'radio'))) {
$default_description = __('Optionally define the minimum and/or maximum character string length. Must be a positive whole number or integer.', 'contact-form-7-dynamic-text-extension') . ' ';
$default_description .= __('Each can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension');
printf(
'<tr><th scope="row"><label>%s</label></th><td><span class="wpcf7dtx-mini-att"><label for="%s">%s</label> <input %s /><input %s /></span> - <span class="wpcf7dtx-mini-att"><label for="%s">%s</label> <input %s /><input %s /></span><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/dynamic-attributes/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
//esc_attr($options['content'] . '-default'), // field id
esc_html__('Character Length', 'contact-form-7-dynamic-text-extension'), // field label
esc_attr($options['content'] . '-minlength'),
esc_html__('Min', 'contact-form-7-dynamic-text-extension'),
wpcf7_format_atts(array(
'type' => 'hidden',
'name' => 'minlength',
'class' => 'option'
)),
wpcf7_format_atts(array(
'type' => 'text',
'name' => 'dtx-minlength',
'id' => $options['content'] . '-minlength',
'class' => 'dtx-option',
'size' => 10
)),
esc_attr($options['content'] . '-maxlength'),
esc_html__('Max', 'contact-form-7-dynamic-text-extension'),
wpcf7_format_atts(array(
'type' => 'hidden',
'name' => 'maxlength',
'class' => 'option'
)),
wpcf7_format_atts(array(
'type' => 'text',
'name' => 'dtx-maxlength',
'id' => $options['content'] . '-maxlength',
'class' => 'dtx-option',
'size' => 10
)),
esc_html($default_description), // Small note below input
esc_attr($utm_source), //UTM source
esc_attr($type), //UTM content
esc_html__('View documentation for Dynamic Attributes', 'contact-form-7-dynamic-text-extension') //Link label
);
}
// Input field - Maxlenth & Minlength attributes (only available for visible text fields)
if (in_array($input_type, array('text', 'email', 'phone', 'url', 'password', 'textarea'))) {
$default_description = __('Optionally define an autocomplete setting by the browser.', 'contact-form-7-dynamic-text-extension') . ' ';
$default_description .= __('Each can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension');
$datalist = array(
'off' => __('Off', 'contact-form-7-dynamic-text-extension'),
'on' => __('On', 'contact-form-7-dynamic-text-extension'),
'name' => __('Full Name', 'contact-form-7-dynamic-text-extension'),
'given-name' => __('First Name', 'contact-form-7-dynamic-text-extension'),
'family-name' => __('Last Name', 'contact-form-7-dynamic-text-extension'),
'honorific-prefix' => __('Honorific prefix or title', 'contact-form-7-dynamic-text-extension'),
'honorific-suffix' => __('Honorific suffix or credentials', 'contact-form-7-dynamic-text-extension'),
'nickname' => __('Nickname', 'contact-form-7-dynamic-text-extension'),
'email' => __('Email Address', 'contact-form-7-dynamic-text-extension'),
'new-password' => __('A new password', 'contact-form-7-dynamic-text-extension'),
'current-password' => __('The current password', 'contact-form-7-dynamic-text-extension'),
'organization-title' => __('Job Title', 'contact-form-7-dynamic-text-extension'),
'organization' => __('Company/Organization Name', 'contact-form-7-dynamic-text-extension'),
'street-address' => __('Full Street Address', 'contact-form-7-dynamic-text-extension'),
'shipping' => __('Full Shipping Address', 'contact-form-7-dynamic-text-extension'),
'billing' => __('Full Billing Address', 'contact-form-7-dynamic-text-extension'),
'address-line1' => __('Address Line 1', 'contact-form-7-dynamic-text-extension'),
'address-line2' => __('Address Line 2', 'contact-form-7-dynamic-text-extension'),
'address-line3' => __('Address Line 3', 'contact-form-7-dynamic-text-extension'),
'address-level1' => __('State', 'contact-form-7-dynamic-text-extension'),
'address-level2' => __('City', 'contact-form-7-dynamic-text-extension'),
'country' => __('Country', 'contact-form-7-dynamic-text-extension'),
'postal-code' => __('Zip Code', 'contact-form-7-dynamic-text-extension'),
'sex' => __('Gender Identity', 'contact-form-7-dynamic-text-extension'),
'tel' => __('Phone Number', 'contact-form-7-dynamic-text-extension'),
'tel-country-code' => __('Country Code', 'contact-form-7-dynamic-text-extension'),
'tel-national' => __('Full phone number without the country code', 'contact-form-7-dynamic-text-extension'),
'tel-area-code' => __('Area code, with country code if applicable', 'contact-form-7-dynamic-text-extension'),
'tel-local' => __('Phone number without the country code or area code', 'contact-form-7-dynamic-text-extension'),
'tel-local-prefix' => __('First part of the local phone number', 'contact-form-7-dynamic-text-extension'),
'tel-local-suffix' => __('Last part of the local phone number', 'contact-form-7-dynamic-text-extension'),
'url' => __('Website URL', 'contact-form-7-dynamic-text-extension'),
'webauthn' => __('Passkeys generated by the Web Authentication API', 'contact-form-7-dynamic-text-extension')
);
$datalist_html = wpcf7dtx_options_html($datalist);
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><datalist id="dtx-autocomplete-datalist">%s</datalist><input %s /><input %s /><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/dynamic-attributes/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
esc_attr($options['content'] . '-autocomplete'), // field id
esc_html__('Auto-complete', 'contact-form-7-dynamic-text-extension'), // field label
wp_kses($datalist_html, array('datalist' => array('id' => array()), 'option' => array('value' => array()))),
wpcf7_format_atts(array(
'type' => 'hidden',
'name' => 'autocomplete',
'class' => 'option'
)),
wpcf7_format_atts(array(
'type' => 'text',
'name' => 'dtx-autocomplete',
'id' => $options['content'] . '-autocomplete',
'class' => 'oneline dtx-option',
'list' => 'dtx-autocomplete-datalist'
)),
esc_html($default_description), // Small note below input
esc_attr($utm_source), //UTM source
esc_attr($type), //UTM content
esc_html__('View documentation for Dynamic Attributes', 'contact-form-7-dynamic-text-extension') //Link label
);
}
//Input field - Autocapitalize attribute (only available for some fields)
if (in_array($input_type, array('text', 'textarea'))) {
$default_description = __('Optionally define an autocapitalize attribute for input when entered via non-typing mechanisms such as virtual keyboards on mobile devices or voice-to-text.', 'contact-form-7-dynamic-text-extension') . ' ';
$default_description .= __('Each can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension');
$datalist = array(
'none' => __('Do not automatically capitlize any text', 'contact-form-7-dynamic-text-extension'),
'off' => __('Do not automatically capitlize any text', 'contact-form-7-dynamic-text-extension'),
'on' => __('Automatically capitalize the first character of each sentence', 'contact-form-7-dynamic-text-extension'),
'sentences' => __('Automatically capitalize the first character of each sentence', 'contact-form-7-dynamic-text-extension'),
'words' => __('Automatically capitalize the first character of each word', 'contact-form-7-dynamic-text-extension'),
'characters' => __('Automatically capitalize every character', 'contact-form-7-dynamic-text-extension'),
);
$datalist_html = wpcf7dtx_options_html($datalist);
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><datalist id="dtx-autocapitalize-datalist">%s</datalist><input %s /><input %s /><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/dynamic-attributes/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
esc_attr($options['content'] . '-autocapitalize'), // field id
esc_html__('Auto-capitalize'), // field label
wp_kses($datalist_html, array('datalist' => array('id' => array()), 'option' => array('value' => array()))),
wpcf7_format_atts(array(
'type' => 'hidden',
'name' => 'autocapitalize',
'class' => 'option'
)),
wpcf7_format_atts(array(
'type' => 'text',
'name' => 'dtx-autocapitalize',
'id' => $options['content'] . '-autocapitalize', // field id
'class' => 'oneline dtx-option',
'list' => 'dtx-autocapitalize-datalist'
)),
esc_html($default_description), // Small note below input
esc_attr($utm_source), //UTM source
esc_attr($type), //UTM content
esc_html__('View documentation for Dynamic Attributes', 'contact-form-7-dynamic-text-extension') //Link label
);
}
//Input field - Readonly attribute (not available for hidden, submit, or quiz fields)
if (!in_array($input_type, array('hidden', 'submit', 'quiz'))) {
if (!in_array($input_type, array('hidden', 'submit', 'label', 'quiz', 'select'))) {
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
esc_attr($options['content'] . '-readonly'), // field id
@@ -412,6 +647,38 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
);
}
//Input field - Disabled attribute (not available for hidden, submit, or quiz fields)
// if (!in_array($input_type, array('hidden', 'submit', 'quiz'))) {
// printf(
// '<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
// esc_attr($options['content'] . '-disabled'), // field id
// esc_html__('Disabled attribute', 'contact-form-7-dynamic-text-extension'), // field Label
// wpcf7_format_atts(array(
// 'type' => 'checkbox',
// 'name' => 'disabled',
// 'id' => $options['content'] . '-disabled',
// 'class' => 'disabledvalue option'
// )),
// esc_html__('Prevent this data from sending on submit', 'contact-form-7-dynamic-text-extension') // checkbox label
// );
// }
//Input field - Autofocus attribute (not available for hidden, submit, or quiz fields)
// if (!in_array($input_type, array('hidden', 'submit', 'quiz'))) {
// printf(
// '<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
// esc_attr($options['content'] . '-autofocus'), // field id
// esc_html__('Autofocus attribute', 'contact-form-7-dynamic-text-extension'), // field Label
// wpcf7_format_atts(array(
// 'type' => 'checkbox',
// 'name' => 'autofocus',
// 'id' => $options['content'] . '-autofocus',
// 'class' => 'autofocusvalue option'
// )),
// wp_kses_post('Automatically focus on this field <small>Use careful consideration for accessibility.</small>', 'contact-form-7-dynamic-text-extension') // checkbox label
// );
// }
// Input field - Page load data attribute (triggers the loading of a frontend script)
printf(
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tag-attribute-after-page-load/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
@@ -462,9 +729,27 @@ function wpcf7dtx_tag_generator($contact_form, $options = '')
}
//Close Form-Tag Generator
if (in_array($input_type, array('hidden', 'submit', 'label', 'reset'))) {
$demo_tag = '<input name="%s"class="tag code" readonly="readonly" onfocus="this.select()" type="text" />';
} else {
$demo_tag = '<textarea name="%s" class="tag code"readonly="readonly" onfocus="this.select()" rows="3" ></textarea>';
}
if (in_array($input_type, array('submit', 'reset', 'label'))) {
$mail_description = esc_html('This value is not submitted in the contact form and should not be used in the mail template.', 'contact-form-7-dynamic-text-extension');
} else {
$mail_description = sprintf(
'<label>%s<input type="text" class="mail-tag code hidden" readonly="readonly" /></label>',
sprintf(
esc_html__('To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.', 'contact-form-7-dynamic-text-extension'),
'<strong><span class="mail-tag"></span></strong>'
)
);
}
printf(
'</tbody></table></fieldset></div><div class="insert-box"><input type="text" name="%s" class="tag code" readonly="readonly" onfocus="this.select()" /><div class="submitbox"><input type="button" class="button button-primary insert-tag" value="%s" /></div><br class="clear" /></div>',
'</tbody></table></fieldset></div><div class="insert-box">' . $demo_tag . '<div class="submitbox"><input type="button" class="button button-primary dtx-insert-tag" value="%s" /></div><br class="clear" />
<p class="description mail-tag">%s</p></div>',
esc_attr($type),
esc_html__('Insert Tag', 'contact-form-7-dynamic-text-extension')
esc_html__('Insert Tag', 'contact-form-7-dynamic-text-extension'),
$mail_description
);
}

View File

@@ -199,24 +199,32 @@ function wpcf7dtx_get_post_id($post_id, $context = 'dtx')
* @param string $value The form tag value.
* @param WPCF7_FormTag|false $tag Optional. Use to look up default value.
* @param string $sanitize Optional. Specify type of sanitization. Default is `auto`.
* @param string $option_name Optional. Specify an option from the $tag to retrieve and decode. Default is `value`.
* @param string $option_pattern Optional. A regular expression pattern or one of the keys of preset patterns. If specified, only options whose value part matches this pattern will be returned.
*
* @return string The dynamic output or the original value, not escaped or sanitized.
*/
function wpcf7dtx_get_dynamic($value, $tag = false, $sanitize = 'auto')
function wpcf7dtx_get_dynamic($value, $tag = false, $sanitize = 'auto', $option_name = 'value', $option_pattern = '')
{
if ($tag !== false) {
$default = $tag->get_option('defaultvalue', '', true);
if (!$default) {
$default = $tag->get_default_option(strval(reset($tag->values)));
if (is_object($tag)) {
if ($option_name != 'value') {
$value = html_entity_decode(urldecode(strval($tag->get_option($option_name, $option_pattern, true))), ENT_QUOTES);
} else {
$default = $tag->get_option('defaultvalue', '', true);
if (!$default) {
$default = $tag->get_default_option(strval(reset($tag->values)));
}
$value = wpcf7_get_hangover($tag->name, $default);
}
$value = wpcf7_get_hangover($tag->name, $default);
}
$value = apply_filters('wpcf7dtx_sanitize', $value, $sanitize);
if (is_string($value) && !empty($value)) {
// If a shortcode was passed as the value, evaluate it and use the result
// If a shortcode was passed as the value, attempt to evaluate itevaluate it and use the result
$shortcode_tag = '[' . $value . ']';
//var_dump('Shortcode tag?', $shortcode_tag);
$shortcode_output = do_shortcode($shortcode_tag); //Shortcode value
if (is_string($shortcode_output) && $shortcode_output != $shortcode_tag) {
//var_dump('Shortcode value?', $shortcode_output);
if ($shortcode_output != $shortcode_tag) {
return apply_filters('wpcf7dtx_sanitize', $shortcode_output, $sanitize);
}
}
@@ -287,8 +295,20 @@ function wpcf7dtx_get_allowed_field_properties($type = 'text', $extra = array())
$allowed_properties['multiple'] = array();
$allowed_properties['dtx-default'] = array();
unset($allowed_properties['type'], $allowed_properties['value']); // Remove invalid select attributes
} elseif ($type == 'label') {
// Properties exclusive to label elements
$allowed_properties['for'] = array();
// Remove invalid label attributes
unset(
$allowed_properties['type'],
$allowed_properties['name'],
$allowed_properties['value'],
$allowed_properties['disabled'],
$allowed_properties['aria-invalid']
);
} else {
// Properties exclusive to text-based inputs
$allowed_properties['autocapitalize'] = array();
$allowed_properties['autocomplete'] = array();
$allowed_properties['list'] = array();
@@ -565,6 +585,33 @@ function wpcf7dtx_textarea_html($atts)
);
}
/**
* Create Options HTML
*
* @since 4.4.0
*
* @param array $options Accepts an associative array of key/value pairs to use as the
* select option's value/label pairs.
* @param bool $selected_value Optional. The value that should be selected by default.
*
* @return string HTML output of options
*/
function wpcf7dtx_options_html($options, $selected_value = '')
{
$html = '';
foreach ($options as $value => $label) {
$dynamic_value = wpcf7dtx_get_dynamic($value);
$dynamic_label = wpcf7dtx_get_dynamic($label);
$html .= sprintf(
'<option value="%1$s"%3$s>%2$s</option>',
esc_attr(apply_filters('wpcf7dtx_escape', $dynamic_value)),
esc_html(apply_filters('wpcf7dtx_escape', $dynamic_label)),
$selected_value == $dynamic_label ? ' selected' : ''
);
}
return $html;
}
/**
* Create Select Field HTML
*

View File

@@ -3,7 +3,7 @@ Contributors: sevenspark, tessawatkinsllc
Donate link: https://just1voice.com/donate/
Tags: Contact Form 7, autofill, prepopulate, dynamic form, form field
Tested up to: 6.5
Stable tag: 4.3.1
Stable tag: 4.4.2
Extends Contact Form 7 by adding dynamic form fields that accepts shortcodes to prepopulate form fields with default values and dynamic placeholders.
@@ -25,6 +25,10 @@ Contact Form 7 is an excellent WordPress plugin and one of the top choices of fr
* Getting custom theme modifications
* Any value using custom shortcodes
The possibilities are endless!
(View Demo)[https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/?preview=1]
For over 10 years, DTX only handled `<input type="text" />` and `<input type="hidden" />` form fields, but version 4 finally introduces more:
* email
@@ -39,8 +43,6 @@ For over 10 years, DTX only handled `<input type="text" />` and `<input type="hi
* date
* submit (yes, a submit button where you can have dynamic text!)
The possibilities are endless!
## WHAT DOES IT DO? ##
DTX provides flexibility to WordPress users in creating dynamic forms in Contact Form 7. DTX comes with several built-in shortcodes that will allow the contact form to be populated from HTTPS GET variable or any info from the `get_bloginfo()` function, among others. See below for included shortcodes.
@@ -320,6 +322,14 @@ Learn more and see examples from [the DTX Knowledge base](https://aurisecreative
== Installation ==
= Minimum Requirements =
To ensure your WordPress installation meets these requirements, you can login to your WordPress website and navigate to *Tools > Site Health* and click on the *Info* tab. Expand the *WordPress*, *Active Plugins*, and *Server* accordions and compare that information with the details below.
* WordPress version 5.5 or greater
* PHP version 7.4 or greater
* [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) version 5.7 or greater
There are three (3) ways to install my plugin: automatically, upload, or manually.
= Install Method 1: Automatic Installation =
@@ -380,11 +390,32 @@ Please check out the [FAQ on our website](https://aurisecreative.com/docs/contac
== Upgrade Notice ==
= 4.3.1 =
Fixed user-reported bugs regarding `dynamic_checkbox` accepting multiple default values, mail template validator, and some PHP warnings. See [the changelog](https://plugins.trac.wordpress.org/browser/contact-form-7-dynamic-text-extension/trunk/changelog.txt) for more details.
= 4.4.2 =
Addressed another PHP warning introduced in version 4.4.0. See [the changelog](https://plugins.trac.wordpress.org/browser/contact-form-7-dynamic-text-extension/trunk/changelog.txt) for more details.
== Changelog ==
= 4.4.2 =
= 4.4.2 =
* Fix: Addressed PHP warning for undefined variable $default_placeholder introduced in version 4.4.0, [see support thread](https://wordpress.org/support/topic/php-warning-undefined-variable-default_placeholder/)
* Minor: Create preview link using WordPress Playground, [check it out](https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/?preview=1)
= 4.4.1 =
* Fix: Addressed PHP warnings for undefined array keys introduced in version 4.4.0, [see support thread](https://wordpress.org/support/topic/tons-of-errors-in-error_log/)
= 4.4.0 =
* Update: Added *Contact Form 7* (CF7) as a requirement as introduced in WordPress version 6.5. This plugin cannot be activated until CF7 is installed and activated.
* Feature: introduced `dynamic_label` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-label/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
* Feature: updated the following attributes to be dynamic: `autocapitalize`, `autocomplete`, `autofocus`, `cols`, `disabled`, `list`, `max`, `maxlength`, `min`, `minlength`, `pattern`, `readonly`, `size`, and `step`. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/dynamic-attributes/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
* Update: Updated the form tag generator for checkboxes and radio buttons to include documentation for the `default` attribute.
* Update: Updated the form tag generator with fields for `min`, `max`, `step`, `minlength`, `maxlength`, and `autocomplete` for appropriate form tags. The `autocomplete` and `autocapitalize` are text fields that uses a `datalist` because I always forget those things...
* Update: Increased the tag generator size to accommodate the new attributes.
* Update: Some form tag generators display the generated form tag in a `textarea` to accommodate lengthy generated form tags.
= 4.3.1 =
* Fix: Resolved the PHP warning regarding `Undefined array key "value" in /.../contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension.php on line 391`, [see support thread](https://wordpress.org/support/topic/undefined-array-key-value-2/).