Ok, so how can I set the default value in registration form *only* but not in user preferences?The template modification does that.
Ok, so how can I set the default value in registration form *only* but not in user preferences?
<script type="text/javascript">
$(document).ready(function(){
$('input[type="checkbox"][name*="[regfield]"][value="[color=red]1[/color]"]').prop('checked',true);
});
</script>
mmm... I've added your piece of code as followAdd this code at the top. You need to specify the fieldid and value of the checkbox:
<script type="text/javascript">
$(document).ready(function(){
$('input[type="checkbox"][name*="[newsletters]"][value="1"]').prop('checked',true);
});
</script>
mmm... I've added your piece of code as follow
Code:<script type="text/javascript"> $(document).ready(function(){ $('input[type="checkbox"][name*="[newsletters]"][value="1"]').prop('checked',true); }); </script>
where 'newsletters' is the field_id, but no dice. What's wrong?
View attachment 90625
<script type="text/javascript">
$(document).ready(function(){
$('input[type="radio"][name*="[regfield]"][value="[color=red]1[/color]"]').prop('checked',true);
});
</script>
Work perfectly! Thank you so much @Jake Bunceyou need to specify "radio" instead of "checkbox"
Anyone? Default custom field box checked?
The javascript example I posted should work.
I too am trying to use a checkbox user field that doesn't apply to the registration page. I was going to use it as an opt-out but that doesn't seem to work for me. The purpose of the checkbox is for an e-mail list. If I make it so if they do check it they are opting out of the e-mail list then when I try to use e-mail users in ACP and leave the user field unchecked in the criteria it still shows the ones that are checked. It would seem a better solution to have a hack that allows me to set the default to checked (opted-in) and then they can uncheck to opt-out. But as I said this won't be part of registration. Is there another hack we can use to check a custom user field by default? Or is there another way I could set the criteria to catch the opted-out option when using ACP to e-mail users? @Jake BunceThis java script is for registration page only? I want to change the default check box to ticked in a custom user field. This field is not on my registration page only in the profile page edit.
That is expected because the template edit only affects the default value in the form. The form must be submitted.
To force an update to existing user records you must run a query:
Rich (BB code):INSERT INTO xf_user_field_value (user_id, field_id, field_value) SELECT user_id, 'field_id', 'value' FROM xf_user ON DUPLICATE KEY UPDATE field_value = VALUES(field_value);
You need to specify the field_id of the custom field and the stored value which you want to write to everyone's profile.
Then rebuild the user cache:
Admin CP -> Tools -> Rebuild Caches -> Rebuild User Caches
INSERT INTO xf_user_field_value (user_id, field_id, field_value)
SELECT user_id, ‘email_announcements’, ‘true’
FROM xf_user
ON DUPLICATE KEY UPDATE
field_value = VALUES(field_value);
DELETE FROM xf_user_field_value (user_id, field_id, field_value)
SELECT user_id, ‘email_announcements’, ‘true’
FROM xf_user
a:5:{s:16:"email_newsletter";s:16:"email_newsletter";s:11:"email_ezine";s:11:"email_ezine";s:19:"email_announcements";s:19:"email_announcements";s:14:"email_contests";s:14:"email_contests";s:17:"email_promotional";s:17:"email_promotional";}
DELETE
FROM xf_user_field_value
WHERE field_id = 'email_announcements'
We use essential cookies to make this site work, and optional cookies to enhance your experience.