大家好,我有2个问题! 我喜欢这种新型的WordPress联络方式,但是他们有些麻烦。 1-名称占位符可以接受任何类型的值(数字-点和所有内容!可以解决此问题的任何解决方案?
2-错误消息显示方式不正确...可能会输出错误-成功消息在类似引导程序模式的弹出窗口中显示?
这是我找到的代码:
function happyforms_message_notices($ location =''){ $ notices = happyforms_get_session()-> get_messages($ location);
if ( ! empty( $notices ) ) : ?>
<div class="happyforms-message-notices">
<?php foreach( $notices as $notice ): ?>
<div class="happyforms-message-notice <?php echo esc_attr( $notice['type'] ); ?>">
<h2><?php echo $notice['message']; ?></h2>
</div>
<?php endforeach; ?>
</div>
<?php
endif;
}
答案 0 :(得分:0)
我是The Theme Foundry的开发人员,是HappyForms的作者。
HappyForms不包含“名称”部分。它还没有提供一种简单的方法来掩盖或过滤用户可以在字段中输入的字符。不过,通过happyforms_the_part_attributes
过滤器是可行的,它使您可以输出pattern
html5属性。
没有内置的方式可以以模态形式输出通知。我想您可以使用Javascript和CSS破解它,尽管您需要修改原始的Javascript主文件(frontend.js),对此我强烈反对。
就这样,您可以在我们的网站和插件注册论坛中与我们取得联系,这可能更适合您的问题。 ;)
答案 1 :(得分:0)
这是很久以前的问题了,不是题外话,但是您可以通过 MonkeyPatch 自己的方式进入 frontend.js,而无需修改原始文件。这也适用于更新,只要打补丁的例程没有得到更新。
我有一个关于 HappyForms 的示例,这是另一个需求,但仍然是您“可以”思考的方式。这里用于在 HappyForms 完成请求后将 Response ajax 到另一个位置。
一般来说,这样的行为不是一个好行为,但有时这是要走的路。
/*****************************************************************************************************************
* .-'-. Monkey Patching - HappyForms - frontend.js
* _/.-.-.\_
* ( ( o o ) ) HappyForms Class / Just add lines of code after the Form send Post-processing
* |/ ' \| Should work with Plugin Updates. Check on Updates of the Happy Forms JS if this functions has
* \ `-´ / changed. If so, the Unchanged CODE lines here has to be changed accordingly.
* /`'''`\
* / \ Must be loaded AFTER the original HappyForms JS - frontend.js
* But before the Form get's initalized by the Page
*
* The used fields can be identified by adding a specific class in the HappyForm Configuration Page
* Use Property CSS classes for that. Here we assume that there are fields for firstname, lastname and
* so on.
******************************************************************************************************************/
HappyForms.Form.prototype.submit = function( e ) { /* Unchanged CODE */
e.preventDefault(); /* Unchanged CODE */
/* Unchanged CODE */
this.$form.addClass( 'happyforms-form--submitting' ); /* Unchanged CODE */
this.$submits.attr( 'disabled', 'disabled' ); /* Unchanged CODE */
/*---------------------------------------------------------------------------------------------------------------*/
/*Additional CODE */ // Get Data from Happy Forms Field identified by css-class
/*Additional CODE */ let sent_data = { firstName : '.formdata-firstname' ,
/*Additional CODE */ lastName : '.formdata-lastname' ,
/*Additional CODE */ phoneNo : '.formdata-phone' ,
/*Additional CODE */ email : '.formdata-email'
/*Additional CODE */ };
/*Additional CODE */ // Fetch values from inputs
/*Additional CODE */ Object.keys(sent_data).forEach((key,i)=>{
/*Additional CODE */ sent_data[key] = jQuery(sent_data[key]).find('input, textarea, select').val();
/*Additional CODE */ });
/*---------------------------------------------------------------------------------------------------------------*/
jQuery.ajax( { /* Unchanged CODE */
type: 'post', /* Unchanged CODE */
data: this.serialize( e.target ), /* Unchanged CODE */
} ).done( (evt)=>{ /* Unchanged CODE */
/* Unchanged CODE */
this.onSubmitComplete( evt ); /* Unchanged CODE */
/* Unchanged CODE */
/*---------------------------------------------------------------------------------------------------------------*/
/*Additional CODE */
/*Additional CODE */ /* Additional subroutine to forward data to Cardess */
/*Additional CODE */ console.log('injected code',evt,sent_data);
/*Additional CODE */
/*Additional CODE */ let ajax_url = '/wp-admin/admin-ajax.php';
/*Additional CODE */ let wp_action = '[individual ajax function]';
/*Additional CODE */
/*Additional CODE */ sent_data.action=wp_action;
/*Additional CODE */
/*Additional CODE */ jQuery.ajax({
/*Additional CODE */ dataType: 'json',
/*Additional CODE */ url: ajax_url,
/*Additional CODE */ method:'post',
/*Additional CODE */ data: sent_data,
/*Additional CODE */ success: (response)=>{ console.log('Response: ',response);
/*Additional CODE */
/*Additional CODE */
/*Additional CODE */ } ,
/*Additional CODE */ error:(arr)=>{ console.warn('Error sending data');
/*Additional CODE */
/*Additional CODE */ }
/*Additional CODE */ });
/*Additional CODE */
/*---------------------------------------------------------------------------------------------------------------*/
/* Unchanged CODE */
} ); /* Unchanged CODE */
}; /* Unchanged CODE */
/*****************************************************************************************************************/
/* Monkey Patching - DONE */
/*****************************************************************************************************************/
我把它放在 Github 上,以防有人需要这样的解决方案:
https://github.com/whilexx/MonkeyPatch-WP-HappyForms-ReuseData