Skip Navigation

[Resolved] Is it possible to create a master "to-do" list that every user can use?

This support ticket is created 7 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#577756

Hi, here's a sample CRED form that shows what I was thinking:

[creduserform class='cred-user-form cred-keep-original']

	[cred_field field='form_messages' value='' class='alert alert-warning']

	[cred_generic_field field='activities' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"123"
}
[/cred_generic_field]


	[cred_field field='form_submit' value='Submit' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[/creduserform]

You can see that all the inputs have been removed except a generic, hidden field. I have hard-coded the Activity ID to 123 for now, but you'll probably use some other shortcode or a URL parameter to determine the relevant Activity ID and pass it in here.

Next, here's cred_save_data hook that will add that activity ID to a User's profile in a repeating numeric field with slug "activities":

add_action('cred_save_data', 'add_user_activity',10,2);
function add_user_activity($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==123)
    {
        if (isset($_POST['activities']))
        {
            // add it to saved post meta
            add_user_meta($post_id, 'wpcf-activities', $_POST['activities']);
        }
    }
}

Change 123 to the numeric ID of the CRED form. $_POST['activities'] is how you access the value passed into the activities field, and add_user_meta() is how you store that value in the User's custom field. It will continue to add new values as the User checks off more and more Activities as completed.

#578011

Christian,

This makes sense.

One question ... you used a generic field, and then added a custom field value into it afterward. I didn't know this was possible. All the information that I found in the forums about making a custom field hidden was to use CSS. I am able to just create a generic field, make it hidden, and add my custom field in the "field=" part?

Thanks so much for your continued support!!

#578017

Not exactly. The generic hidden field isn't related programmatically to the real custom field. The generic field name "activities" in this case is arbitrary, but "wpcf-activities" is the prefixed slug of the actual custom field. If you want to use a generic hidden field in a form instead of a real field, then you must add custom code like we have here to capture the generic value and then store it in the real custom field using update_post_meta or add_post_meta. Otherwise, the value in the hidden field will not be saved. CSS is a simpler approach to hide a real custom field.

#579165

I have yet to implement this. I had to jump off of this project, but I'd like to keep this support ticket open. I will be getting back to this very soon.

Thanks!

#579205

No problem, I will stand by for your update.