Home › Forums › Quform WordPress › Auto-Check Checkboxes for individual users
- This topic has 14 replies, 2 voices, and was last updated 11 years, 4 months ago by jrjacobs24.
- AuthorPosts
- June 5, 2013 at 6:57 am #4683jrjacobs24Participant
I am currently trying to build a personal pull list system for a comic book store website I am building. I want each user to be able to log on and go through a list of comics and check the ones they want to subscribe to. After saving their list, I want to have the user be able to log off, come back later and their options still be checked. They can then either check more options or uncheck previous options. I have read over the “Getting Form Values” and “Dynamic Default Value” pages and various other forum posts, but haven’t been able to find anything that would fit this situation. I am not overly proficient in PHP but have been trying to get the jist.
I know doing such a thing probably isn’t that tough and it’s probably pretty similar to saving settings for a user’s profile, but I don’t really know how to do that. Any suggestions?
June 5, 2013 at 11:17 am #4692AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 5, 2013 at 6:24 pm #4710jrjacobs24ParticipantThis looks great! I’m going to definitely try this out. I do have one question though. I have each separate publisher (i.e. Marvel, DC, Image, etc.) as a separate set of checkboxes in the form. So Marvel would be iphorm_1_1 and DC would be iphorm_1_2 and so forth, so for the line:
$comics = $form->getValue('iphorm_1_1');
Could I just use the getValues(); method that is described in the Getting Form Values tutorial?
So it’d be:
$comics = $form->getValues();
Thanks again for your help!
June 5, 2013 at 6:31 pm #4711jrjacobs24ParticipantOk, I tried using
$comics = $form->getValues();
and it didn’t work. It might just be that I had to change something else in the code that I don’t know about. Good news is, when I used the original code you posted, it did save the form results correctly for the comics listed under Marvel, so at least we know it’s working. Not to just get it going for each publisher.
June 5, 2013 at 6:35 pm #4713AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 5, 2013 at 6:39 pm #4714jrjacobs24ParticipantAlso, I set the parameters for both Marvel and DC to “comics”. Not sure if having the same parameter for two separate elements is allowed or not. Sorry, just trying to give you as much info as I can think might help.
June 5, 2013 at 6:40 pm #4715jrjacobs24ParticipantOk, I really appreciate it! Thank you.
June 6, 2013 at 11:29 am #4744AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 6, 2013 at 9:15 pm #4756jrjacobs24ParticipantThat worked perfectly! Thank you so much! Best customer service I’ve had for a WordPress plugin so far.
July 2, 2013 at 6:16 pm #5088jrjacobs24ParticipantOk, I’ve ran into another problem involving this situation. The code worked perfectly until we added more publishers. I went in and added to the code all the necessary form id’s, but what I keep getting an error and my form info is not being displayed like it was when it was working. My thinking is that since not every entry is going to return a value (someone might not select a comic (value) from a publisher (entry)) that the array is not functioning properly. My code looks like this at the moment:
function mytheme_set_subscribed_comics($form)
{
if (is_user_logged_in()) {
global $current_user;
$comics = array_merge(
$form->getValue('iphorm_1_1'),
$form->getValue('iphorm_1_2'),
$form->getValue('iphorm_1_3'),
$form->getValue('iphorm_1_4'),
$form->getValue('iphorm_1_5'),
$form->getValue('iphorm_1_6'),
$form->getValue('iphorm_1_7'),
$form->getValue('iphorm_1_8'),
$form->getValue('iphorm_1_9'),
$form->getValue('iphorm_1_10'),
$form->getValue('iphorm_1_11'),
$form->getValue('iphorm_1_12'),
$form->getValue('iphorm_1_13'),
$form->getValue('iphorm_1_14'),
$form->getValue('iphorm_1_15'),
$form->getValue('iphorm_1_16'),
$form->getValue('iphorm_1_17'),
$form->getValue('iphorm_1_18'),
$form->getValue('iphorm_1_19'),
$form->getValue('iphorm_1_20'),
$form->getValue('iphorm_1_21'),
$form->getValue('iphorm_1_22'),
$form->getValue('iphorm_1_23'),
$form->getValue('iphorm_1_24'),
$form->getValue('iphorm_1_25'),
$form->getValue('iphorm_1_26'),
$form->getValue('iphorm_1_27'),
$form->getValue('iphorm_1_28'),
$form->getValue('iphorm_1_29')
);
update_user_meta($current_user->ID, 'subscribed_comics', $comics);
}
}
add_action('iphorm_post_process_1', 'mytheme_set_subscribed_comics');
function mytheme_get_subscribed_comics($value)
{
if (is_user_logged_in()) {
global $current_user;
$value = get_user_meta($current_user->ID, 'subscribed_comics', true);
}
return $value;
}add_action('iphorm_element_value_comics', 'mytheme_get_subscribed_comics');
What should I do to make it ok that some entries won’t return a value? (i.e. I choose comics from Marvel (iphorm_1_1), DC (iphorm_1_2) and Image (iphorm_1_3) but not Dark Horse (iphorm_1_4))
I hope this wasn’t too confusing haha Thanks!
July 5, 2013 at 12:16 pm #5125AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 5, 2013 at 4:14 pm #5139jrjacobs24ParticipantThank you again, Ally, for getting back to me. I’m attaching two images to show you both the error I’m getting and the segment of code that it’s referring to so you’ll have the line numbers. Thanks again!
Attachments:
You must be logged in to view attached files.July 5, 2013 at 4:14 pm #5141jrjacobs24ParticipantHere’s the code:
Attachments:
You must be logged in to view attached files.July 6, 2013 at 8:58 am #5155AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 8, 2013 at 3:27 am #5167jrjacobs24ParticipantThat seems to have done it! Thanks again, Ally! You’ve been a life-saver on this project. I’ll definitely highly recommend Quform in the future.
- AuthorPosts
- You must be logged in to reply to this topic.