CRED plugin allows you to build front-end forms for creating and editing content. These forms can include all the fields that belong to the content and display them with your HTML styling. CRED forms also support input validation and automatic email notifications.
When you ask for help or report issues, make sure to tell us the structure and the settings of your form.
Viewing 15 topics - 526 through 540 (of 721 total)
Problem:
I would like the user to be able to upload a file into a post. The field is set to allow multiple entries.
I would like the form to allow the user to upload a new file without displaying (and allowing for the deletion of) files already stored in that field for that post. So, the option would be simply to "add new". Is that possible
Solution:
That's actually not possible. But you can use two repeatable image fields and some custom code to achieve this. For example, create two repeatable image fields:
- Field Images, which will actually hold the images.
- Field Temporary_images, which will be used in the form each time.
And upon form submission, you can implement custom code that will hook into the cred_save_data action, then you can copy the values of the "Temporary_images" field into the "Images" field, and empty the values of the "Temporary_images" field. Does it make sense? https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
Problem: I have a Form used to create posts. There is a taxonomy field in the Form so Users can choose which term(s) to apply to the new post. I would like to display only terms that were created by the current logged-in User.
Solution: Since WordPress does not natively track the author of each term, you must programmatically add that term author ID in a custom field associated with each term when the term is created. Once that custom field value is added successfully, you can then use the get_terms hook to filter the terms available in the taxonomy field options. Here is an example of the code:
// RESTRICT TAXONOMY TERM FIELD OPTIONS TO USER'S OWN TERMS BY TERM FIELD VALUE
// https://toolset.com/forums/topic/show-only-terms-created-by-current-user-in-taxonomy-dropdown-on-the-form/
function tssupp_terms_by_current_user( $terms, $taxonomies, $args, $term_query ){
$pages = array( 123, 456 ); // comma-separated list of page IDs where this Form is displayed
$taxonomy_slug = 'tax-slug'; // slug of the taxonomy to filter
$author_field_slug = 'field-slug'; // slug of the post author id field
// you should not edit below this line
// loop over each term and get its custom field value
// compare that field value against the current user id and drop any terms with a different value
$user_id = get_current_user_id();
if ( is_page( $pages ) && $taxonomies[0] == $taxonomy_slug ) {
foreach($terms as $key=>$term) {
$term_author = get_term_meta($term->term_id, 'wpcf-' . $author_field_slug, true);
if( $term_author != $user_id ) {
unset( $terms[$key] );
}
}
}
return $terms;
}
add_filter( 'get_terms', 'tssupp_terms_by_current_user',10,4);