The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Post category and tags from form
I thought this was going to be really difficult, but was quite simple. Hopefully I will save someone some time.
Create form fields for keyword tags and categories and create them as 'Tag' type. I didn't know it was there until yesterday. They can then be selected as input fields and mapped to the post's taxonomy fields.
In the form's Settings=>Create Post tab, go to the bottom and map these two fields to the WP taxonomy types. I made the following customisations to this basic start
TAGS I wanted to invite several tags, but have limited them to a max of three words per tag with the following code. To do this I collected the tags in five different fields.
add_filter('frm_validate_field_entry', 'field_length_3', 10, 3);
function field_length_3($errors, $posted_field, $posted_value){
if(in_array($posted_field->id, array(864, 865, 866, 867, 868))){
$words = explode(' ', $posted_value);
$count = count($words);
if($count > 3)
$errors['field'. $posted_field->id] = '3 words only for keyword tags, Sorry';
}
return $errors;
}
I then combined the tags into one hidden field (tag type) with commas separating them (with much help from Jamie).
add_filter('frm_validate_field_entry', 'combine_with_commas', 8, 3);
function combine_with_commas($errors, $posted_field, $posted_value){
if ( $posted_field->id == 987 ) {
$field_864 = $_POST['item_meta'][864];
$field_865 = $_POST['item_meta'][865];
$field_866 = $_POST['item_meta'][866];
$field_867 = $_POST['item_meta'][867];
$field_868 = $_POST['item_meta'][868];
$field_987 = $_POST['item_meta'][987];
$_POST['item_meta'][987] = $_POST['item_meta'][864] . ( !empty($field_865) ? ', ' . $field_865 : '') . ( !empty($field_866) ? ', ' . $field_866 : '') . ( !empty($field_867) ? ', ' . $field_867 : '') . ( !empty($field_868) ? ', ' . $field_868 : '');
} return $errors;
}
CATEGORIES I wanted users to select only one category from a predetermined list. I read some complicated looking posts, but I found a simpler way that works. My categories (128 of them) are in a dropdown list. I created a hidden field (tag type) and then copied the value chosen in the dropdown list into the hidden tag field with the following code.
add_filter('frm_validate_field_entry', 'frm_copy_field', 8, 3);
function frm_copy_field($errors, $posted_field, $posted_value){
if(($posted_field->id == 960)&&($_POST['frm_action'] == 'create')){
$_POST['item_meta'][960] = $_POST['item_meta'][857];
}
return $errors;
}
I've bothered the support staff with so many questions lately, I thought that I should add something while it's fresh in my mind.
April 14, 2014 at 9:12 am
This code is it must be pasting to function .php ?
Thank you
April 14, 2014 at 9:43 am
All of those snippets are added to the functions.php file - preferably in your theme child.
April 14, 2014 at 9:47 am
Ok thanks for your reply ,so I just need to copy all of it to pasting on function.php .
Thanks a lot !
April 14, 2014 at 10:00 am
Yes, but any field ID's need changing to your own
Discussion closed.