Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1426901
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI cannot seem to find a solution, neither here nor Google. A client requested to have ONE name field in his CF7 Form but once the email is sent it needs to bcome TWO fields.
Example: [your-name] becomes [first-name] [surname] somewhere hidden in the form.
How is this even possible?
EDIT
I have built something with webhooks but for some reason it does not submit the data.
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";
}
}
}
In my Contact Form I have the following hidden fields
[hidden first_name]
[hidden last_name]
Both fields are declared in the email too as [first_name] [last_name] but the name-stripping does not pull through
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI cannot seem to find a solution, neither here nor Google. A client requested to have ONE name field in his CF7 Form but once the email is sent it needs to bcome TWO fields.
Example: [your-name] becomes [first-name] [surname] somewhere hidden in the form.
How is this even possible?
EDIT
I have built something with webhooks but for some reason it does not submit the data.
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";
}
}
}
In my Contact Form I have the following hidden fields
[hidden first_name]
[hidden last_name]
Both fields are declared in the email too as [first_name] [last_name] but the name-stripping does not pull through
Share Improve this question edited May 16, 2019 at 19:54 mad2kx asked May 16, 2019 at 10:30 mad2kxmad2kx 1722 silver badges14 bronze badges 5 |1 Answer
Reset to default -1could be possible with jQuery. This Idea is to add a Hidden field and set value to it with 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.
}
});
then you can use the hidden field in email.
本文标签: plugin contact form 7CF7 SplitSeparate fields
版权声明:本文标题:plugin contact form 7 - CF7 SplitSeparate fields 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745486742a2660417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$posted_data["first_name"] = $first_name;
etc. I don't know CF7 well enough to know if that's going to work though. – Rup Commented May 17, 2019 at 13:41