How to send 'no' in form when checkbox isn't checked in WordPress

百般思念 提交于 2020-01-06 15:20:56

问题


In contact form 7 plugin of WordPress, Is it possible to send custom message to mail based on checkbox value. In my form I have, subscribe to newsletter checkbox. When user checks the checkbox, subscribe to newsletter is coming as 'Yes' in mail. Now I want to send subscribe to newsletter as 'No' when user doesn't check the checkbox.

Is it possible. I tried and am still searching for the answer in google but to no avail.Any help/suggestion is welcome. Thanks in advance.


回答1:


Finally got the solution.

add_action("wpcf7_posted_data", "wpcf7_modify_this");
function wpcf7_modify_this($posted_data) {
    /* if checkbox isn't checked send Nej to mail */
    if ($posted_data['checkbox-829'][0] == "")
        $posted_data['checkbox-829'][0] = "Nej";

    return $posted_data;
}

I got this solution from answer of DACrosby here.



来源:https://stackoverflow.com/questions/41955282/how-to-send-no-in-form-when-checkbox-isnt-checked-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!