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 - 841 through 855 (of 861 total)
Problem:
I have two upload fields on CRED form, one for image file and one for pdf file type only.
I want to validate what users upload in each field. Solution:
add_filter('cred_form_ajax_upload_validate','my_validation',10,2);
function my_validation($error_fields, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$error_fields;
//validate if specific form
if ($form_data['id']==5)
{
//if the file field is set, and not type jpeg
if (isset($fields['wpcf-toolset-file']['field_data']['type']) && $fields['wpcf-toolset-file']['field_data']['type'] != 'image/jpeg')
{
$errors['wpcf-toolset-file'] = 'Wrong file type';
}
//if the image field is set, and bigger than one
if (isset( $fields['wpcf-toolset-image']['field_data']['size'] ) && $fields['wpcf-toolset-image']['field_data']['size'] > 1)
{
$errors['wpcf-toolset-image'] = 'Wrong size image';
}
}
//return result
return array($fields,$errors);
}
Problem: I have a CRED form set up that allows users to update a post's status. The User can select a status that is different from the form's post status settings. Incorrect email notifications are being sent when the email status is different from the form's post status settings.
Solution: Change the form's post status settings to "Keep original status" to prevent these unnecessary draft emails from being sent.
There isn't such a built-in feature within CRED,
As a workaround, you can create another custom field, for example "show-error-field", put it into the CRED form, and hide it with CSS codes, use it in your PHP codes, replace this line from:
$errors['member-arts-culture']= 'You must choose at least one category';
To:
$errors['show-error-field']= 'You must choose at least one category';
Problem:
1.) Is there a way to use Zapier to pass the values of the form upon submitting to my email service provider, such as ActiveCampaign?
2.) Is there a way to re-create the form in this GIF?
On the backend, for each value (e.g. 1 BR, 2 BR, etc.) or value-mix (e.g. 1 BR, 1 BA) there is a corresponding URL that I can associate with that combination
3.) For both of these, how difficult is it to create something like this with CRED?
Solution:
1. We offer the cred_save_data API hook that can be used to capture any information submitted in a form, but there is no integration specific to Zapier or ActiveCampaign. With custom code, it may be possible to send that data to another 3rd-party tool using PHP.
2. This type of custom form interface will require a significant amount of custom code. The types of CRED form inputs we offer are text fields, select fields, radio groups, and checkboxes. The types of inputs I see in this GIF are range sliders and images that act like radio controls. Neither of these is supported by CRED and must be built from scratch using custom HTML, CSS and JavaScript.
It's not standard behavior in CRED to redirect to a URL containing all the selected URL parameters, but it's possible with some custom code. Assuming these are custom field values, then you can use the cred_success_redirect API hook to redirect the User to any URL you'd like, including URL parameters based on the values they chose in the CRED form.
3. Advanced knowledge of PHP, JavaScript, HTML and CSS is required to pull this off in CRED. It cannot be accomplished simply using the wp-admin interface.
Problem: I am using cred_save_data to perform some actions after form submission, but the update_post_meta calls do not seem to be working as expected.
Solution: Check your code syntax, compare $_POST keys, and debug using the server logs.
Problem: I am using CRED to create child posts. I would like to programmatically set the child post title based on the parent post title. I'm using the beta plugins.
Solution:
The post data key for accessing the parent post's ID has changed in the M2M betas. You can now use the format "@" + relationshipslug + "_parent". In this case the relationship slug is member_visitation, so the key is "@member_visitation_parent".
add_action('cred_save_data', 'copy_parent_title_to_child',10,2);
function copy_parent_title_to_child($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==429)
{
if (isset($_POST['@member_visitation_parent']))
{
$my_post = array(
'ID' => $post_id,
'post_title' => get_the_title($_POST['@member_visitation_parent'])
);
wp_update_post( $my_post );
}
}
}