Skip Navigation

[Resolved] Hide/Lock/Disable field?

This support ticket is created 7 years, 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Shane 7 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#433567

Hello

I have a radio field with three options:

- pending
- approved
- rejected

I have created a Cred form. when sent I want the default value to be "pending" and I don't want users to be able to change the value.

I know it is possible to add it this way :
[cred_field field='report-status' post='report' value='pending' urlparam='']
Then use css to hide it ....

But I want something more advanced that would give users no way to change the field value.

Any advice how to do that?

Thanks

#433692

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Boris,

Thank you for contacting our support forum.

You can do this with some jQuery. Please have a look at the link below and let me know if it helps.
http://stackoverflow.com/questions/1362153/how-can-i-use-jquery-to-make-an-input-readonly

Thanks,
Shane

#433697

But anyone disable Javascript at his browser will be able to bypass that. isn't it?

A good solution for me could be to add a default custom field for every post published through my cred form. Is it possible?

Thanks

#433736

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Boris,

This would be possible but it would need to be done using a CRED hook to populate the field when the post is created.

So create a custom field in Types and don't add that field to the CRED form.

Then you can set the field value using the CRED hook when the form is submitted.

Please let me know if this helps.
Thanks,
Shane

#433738

Please can you explain more how to implement that?

#433757

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Boris,

What we will be using are these two functions.
https://toolset.com/documentation/user-guides/cred-api/#csd

https://codex.wordpress.org/Function_Reference/update_post_meta

So once you create the custom field in Types then you just write the hook like this

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12)
    {
   update_post_meta($post_id, "wpcf-custom-field", "value to add");
        }
    }
}

Add the above your functions.php file change the 12 to the ID of your CRED form. Also you will need to change the wpcf-custom-field to the slug of your custom field keeping the wpcf- prefix and finally setting the value to add.

Please let me know if this helps.
Thanks,
Shane

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.