You can do this, but I am not certain of the unintended consequences. Since this is a checkbox field, it's not expecting an email address. One thing that will break for sure is the admin entry display (where there is normally a check mark when a box is checked.)
However, if you have a form with two fields, email address in field one, and the opt-in check box as field two, and a value for the check box of 'opt-in' (the exact text is important), you can use this code to copy the email address to the opt-in check box field, when the box was checked. Add this code to your theme's functions.php. Change the 163 to your form ID and if your fields are not #1 for email and #2 for check box, you will need to adjust that as well:
[php]
add_action('gform_pre_submission_163', 'opt_in_to_email');
function opt_in_to_email($form) {
if('opt-in' == rgpost('input_2_1'))
$_POST['input_2_1'] = rgpost('input_1');
}
Posted 12 years ago on Tuesday September 18, 2012 |
Permalink