我似乎找不到解决办法,无论是在这里还是谷歌。一个客户要求在他的CF7表单中有一个名字字段,但是一旦电子邮件被发送,它需要有两个字段。
示例:变成隐藏在表单中的某个地方。
这怎么可能?
<#>编辑
我已经用webhooks构建了一些东西,但是由于某种原因,它没有提交数据。
add_action( 'wpcf7_before_send_mail', 'wpcf7_strip_name', 10, 1 );
function wpcf7_strip_name($contact_form){
$submission = WPCF7_Submission::get_instance();
$posted_data = $submission->get_posted_data();
if ($posted_data["your-name"]){
$name = trim($posted_data["your-name"]);
$last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name);
$first_name = trim( preg_replace('#'.$last_name.'#', '', $name ) );
// Set default value for last name if none is provided
if ($last_name == NULL ){
$last_name = "Not Provided";
}
}
}在我的联系人表单中,我有以下隐藏字段
[hidden first_name]
[hidden last_name]这两个字段也会在电子邮件中声明,但是名称剥离不会通过。
发布于 2019-05-16 11:20:15
可能与jQuery有关。这个想法是添加一个隐藏字段并使用jquery为其设置值。
$("#name_field_id").focusout(function(){
str = $(this).val();
if(str){
s = str.split(/(?<=^\S+)\s/); //split string in name field after first space found.
$("#hidden_field_id").val(s[1]); //s[1] value after the first space set to hidden field.
}
});然后,您可以在电子邮件中使用隐藏字段。
https://wordpress.stackexchange.com/questions/338026
复制相似问题