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 - 166 through 180 (of 356 total)
You can make a list of foul words and check against the submitted content and if found remove those words and then assign the filtered content to the field.
Problem:
The user would like to validate an image field(repeatable) in a Toolset form for the image type, size, dimensions, and number of images
Solution:
This will require custom code. Check this example code:
add_action('cred_form_validate', 'my_image_validation_func',10,2);
function my_image_validation_func($error_fields, $form_data) {
// all the valid file types
$file_types = array('image/jpeg','image/png','image/jpg');
$max_size = 5 * 1024 * 1024;
$forms = array( 1806 );
// Field data are field values and errors
list($fields,$errors)=$error_fields;
if (in_array($form_data['id'], $forms ) && (isset($_FILES['wpcf-book-images']['type']))) {
// 1. Minimum number of photos is '3'.
if ( count( $_FILES['wpcf-book-images']['name'] ) < 3 ) {
$errors['wpcf-book-images'] = 'Add at least 3 images';
return array( $fields, $errors );
}
// 2. Dimensions of the photo should be at least 350 (height) x 350 (width).
foreach ( $_FILES['wpcf-book-images']['tmp_name'] as $tmp_image ) {
$sizes = getimagesize( $tmp_image );
if ( $sizes[0] < 350 || $sizes[1] < 350 ) {
$errors['wpcf-book-images'] = 'An image is too small. Images should be at least 350x350';
return array( $fields, $errors );
}
}
// 3. The file types should be JPG, PNG and JPEG.
foreach ( $_FILES['wpcf-book-images']['type'] as $type ) {
if ( !in_array( $type, $file_types ) ) {
$errors['wpcf-book-images'] = 'Image file type is not supported: ' . $type;
return array( $fields, $errors );
}
}
// 4. Maximum file size should be 5MB.
foreach ( $_FILES['wpcf-book-images']['size'] as $size ) {
if ( $size >= $max_size ) {
$errors['wpcf-book-images'] = 'An Image is too big. Images should less than 5MB';
return array( $fields, $errors );
}
}
}
//return result
return array($fields,$errors);
}