Auto-Check Checkboxes for individual users

Home Forums Quform WordPress Auto-Check Checkboxes for individual users

This topic is: resolved
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #4683
    jrjacobs24
    Participant

    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?

    #4692
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4710
    jrjacobs24
    Participant

    This 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!

    #4711
    jrjacobs24
    Participant

    Ok, 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.

    #4713
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4714
    jrjacobs24
    Participant

    Also, 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.

    #4715
    jrjacobs24
    Participant

    Ok, I really appreciate it! Thank you.

    #4744
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4756
    jrjacobs24
    Participant

    That worked perfectly! Thank you so much! Best customer service I’ve had for a WordPress plugin so far.

    #5088
    jrjacobs24
    Participant

    Ok, 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!

    #5125
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #5139
    jrjacobs24
    Participant

    Thank 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.
    #5141
    jrjacobs24
    Participant

    Here’s the code:

    Attachments:
    You must be logged in to view attached files.
    #5155
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #5167
    jrjacobs24
    Participant

    That 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.

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy