CRED plugin provides an API, making it easy to customize your post or user forms. The API includes hooks (actions and filters) to accomplish specific tasks using PHP code.
When you ask for help or report issues, make sure to tell us all related information about your form and what you want to achieve.
Viewing 15 topics - 691 through 705 (of 732 total)
I have a CRED User form that I want to use only for updating email address by a member.
But, even using the Generate Form wizard, the current email address is shown in the field. I have labeled the field "Enter New Email Address", so it should not show the current email value.
Solution:
There isn't such a built-in feature within Toolset form for editing user, the email field will display existed user's email value by default.
Problem: I have a View of published posts, and I would like to include a button on the front-end of the site to set the post status to be "Draft" instead of "Publish".
Solution: You can do this with a Form that is set to Draft status. Remove all the visible inputs except the Submit button and change the button to say "Draft" or something else.
Problem: I would like to use the Forms API to validate each image that is uploaded in a single or repeating custom field. It doesn't seem to be working, in the logs I see a PHP notice about trying to get property of a non-object.
Solution: Make sure the User has permission to publish Media if you are using Toolset Access Control. Make sure the Form's markup structure doesn't include any extra closing div tags. Use the following custom code to validate a repeating image field:
add_filter('cred_form_ajax_upload_validate','rep_img_size_validation',10,2);
function rep_img_size_validation($error_fields, $form_data)
{
error_log(' validation script is invoked ');
$forms = array( 29, 49 );
$size = 1024000;
$field_slug = 'your-repeating-image-slug';
$error_msg = 'Maximum size is 1MB, please try again.';
//field data are field values and errors
list($fields,$errors)=$error_fields;
//validate if specific form
if (in_array( $form_data['id'], $forms ) && isset($fields['wpcf-' . $field_slug]['field_data']['size']))
{
//check if this field instance img is bigger than $size (bytes)
$instance_size = array_pop($fields['wpcf-' . $field_slug]['field_data']['size']);
if ( $instance_size > $size )
{
//display error message for this field instance
$errors['wpcf-' . $field_slug] = $error_msg;
}
}
//return result
return array($fields,$errors);
}
To validate a single field, copy the code above and make the following adjustments:
- Change the function names to prevent a PHP error
- Change the field slug
- Remove array_pop from the instance_size definition like this:
// for repeating images
// $instance_size = array_pop($fields['wpcf-' . $field_slug]['field_data']['size']);
// for single images
$instance_size = $fields['wpcf-' . $field_slug]['field_data']['size'];