Hello,
I understand how to let users assign which categories their post will belong to as described here:
In addition to this I need to assign the user’s post to a specific category (the same category each time)
One way I have thought that might work is to add an extra dropdown field containing a single element on my form, assign it the required category using the method described in the URL above, then hide the drop down from users via css (display:none) since it will always need to be set to the same value hence the user never needs to see it.
Is there a better way that I am missing?
ie. I can’t seem to figure out how to assign a hidden field on my form to a specific category value on the ‘Create Post’ screen.
Many thanks,
Natacha




October 5, 2012 at 11:15 am
There has been a change made for the next release to allow multiple fields to work correctly when mapped to the same taxonomy. So, you can make this change now by opening formidable/pro/classes/models/FrmProEntryMeta.php and changing line 272 from:
$_POST['frm_tax_input'][$tax_type] = $value;
to:
if(!isset($_POST['frm_tax_input'][$tax_type])){ $_POST['frm_tax_input'][$tax_type] = $value; }else if(!empty($value)){ $_POST['frm_tax_input'][$tax_type] = array_merge($_POST['frm_tax_input'][$tax_type], array_map('trim', explode(',', $value))); }After making this change, you can create a second field. You can find instructions here for setting a default category:
http://formidablepro.com/knowledgebase/create-a-post-form-and-display-the-results/#kb-how-to-set-a-default-category
October 16, 2012 at 2:11 am
HI there,
Sorry, but I am still having all sorts of problems with assigning categories to posts.
My problem is that my form no longer shows the categories in the front end - the field item shows the field title and nothing else.
I followed yor instructions exactly here and it did work for me once:
http://formidablepro.com/knowledgebase/create-a-post-form-and-display-the-results/#kb-how-to-set-a-default-category
Then I moved on to coding other parts of my form, but now the categories no longer show up as radio items on my form, no matter what I do. (note I have not applied your code update above)
I've gone through every forum post on this issue - I just can't seem to figure out why - doing a view source, the radio items are not being written to the frontend at all, nor on the 'preview' form link.
Does the form field to be named in a specific way?
Any clues on why this is happening?
We have a lot of categories and subcategories on the site - I'm only trying to show 2 subcategories on the form.
I don't know if this is a cause of the issue.
As I said I have seen this working in the past but cannot figure out why suddenly this is no longer working.
I have also tried changing the field type in the form to checkbox/radio/dropdown but nothing works. The taxonomies in the settings page are also set up to the correct field name.
Ahhh?
I'm a hard core programmer, so I'm tempted to manually code the action that adds the categories to the post after the post is submitted via an action but I know this should work :(
Thanks,
Natacha
October 16, 2012 at 2:18 am
Sorry I should also mention that the categories do not display in the form editor (build tab) either. I can see them in the settings tab but that's it
October 16, 2012 at 2:25 am
Ok after all that ranting I figured out my problem - I had the parent category checked to not show, hence I guess by default you then don't show the children.
So my question (ignoring all my rambling above) :
Is it possible to show only the subcategories as radio items, but not show the parent items.
Since it is confusing as my radio buttons show up all unselected as:
- event guide
-Fashion
- Music
but event-guide is the parent category and they will always fall into this
Will there be issues if I hide it using css?
ps. You should look at your UI for the way you handle dynamically adding categories to form items.
This should probably be located on the form editor area, not in the settings - so many people seem confused with the way this works. I think the way you had it prevously in 2011 was a little more obvious.
October 16, 2012 at 10:32 am
Yes you can hide the parent categories and only show the sub-categories. I explain how on the second to last response in this thread: http://formidablepro.com/help-desk/mask-hide-a-parent-category-in-a-form/
Please read through those instructions and let us know if you have any other questions.
October 16, 2012 at 11:58 pm
Hello,
I followed your exact instructions from that thread.
The subcategory choice never gets saved in the post, only the parent category.
So for the parent 'event guide' with 2 subcats 'Fashion' and 'Music':-
- event guide
-Fashion
- Music
neither 'Fashion' nor 'Music' category ever gets saved/associated with the post.
The post is only categorised as the parent 'event guide'.
Any ideas?
Thanks,
Natacha
October 17, 2012 at 1:21 am
Hello,
Ok I finally got the subcat to save. It seems that it will not work if the following is set up:
On the Form settings page, create posts tab I had set 'Custom Fields' to equal the subcategory field from the taxonomy added in the step above it (because I use this elsewhere). If this is the case, the taxonomy I added in the previous step gets removed when I save. I didn't notice it being removed since whenever we save, the first tab is redisplayed rather than staying on the 'create posts' tab so I missed noticing this.
So now that is sorted, the subcat is saved but my final problem is that I am back where I started
- I simply cannot hide the parent category from showing.
If I tick the checkbox for the parent to make it not show, no subcats show on my form at all.
If I untick the checkbox, the subcats AND the parent shows.
Can you confirm if this is a bug?
ie. adding the parent category and setting it as admin to not show on the form seems to do nothing except for add that parent category for the post which I don't need. It does not affect the parent from showing next to the subcat fields.
I looked at the code and there is no way I can hide the parent field using css - there is no id or possible way I can assign a css style element to only the parent field.
Any other suggestions?
Thanks,
Natacha
October 17, 2012 at 1:25 am
I do see you mention this on the page:
NOTE: if the parent is excluded, child categories will be automatically excluded.
But my original question was how to show only the child categories and not show the parent on the form.
October 17, 2012 at 7:31 am
So after running around in circles I found I just couldn't get the categories to show correctly, as described above.
I'm still convinced this might be a bug so let me know if you need me to apply any further tests to help out with testing.
I gave up and save the categories manually using a little bit of code and an action hook.
That way I have full control of which categories are displayed in my form and how they are displayed.
I'll post my solution in case it helps anyone else out there with issues on setting up and running categories and subcategories into the form - I know so many other solutions on here have helped me in the past.
1. I set up a basic radio button field with 2 options - Music and Fashion
2. Set up this action hook in functions.php :-
function after_entry_created($entry_id, $form_id) {
//get the ID of event post that was created by formidable pro
global $frmdb;
$post_id = $frmdb->get_var( $frmdb->entries, array('id' => $entry_id), 'post_id');
$eventtype = $_POST['item_meta'][131]; //grab which event radio btn was selected
switch($eventtype) { //store the slug for the cat (event type) chosen
case 'Music' : $category = 'event-music'; break; //3781
case 'Fashion' : $category = 'event-fashion'; break; //3780
default : $category = 'event-fashion'; break; //3780
}
$cat_id = term_exists($category, 'category', 'event-guide'); //get the id for the chosen subcat
wp_set_post_terms($post_id, array($cat_id), 'category'); //save the category for the new post
}
add_filter('frm_after_create_entry', 'after_entry_created', 50, 2);
*Ensure the above hook doesn't fire too early otherwise it will fire before the post is actually created, so 50 is usually a good number.
October 17, 2012 at 12:48 pm
Thanks for sharing this. I will do some more testing with the category displays. The radio buttons may have been complicating things. If I need you to help test things out, I'll let you know.
October 17, 2012 at 4:40 pm
I was getting the same behaviour on both radios and checkboxes.
Thanks,
Natacha
October 18, 2012 at 10:57 am
Okay, We'll look into this. Thanks for your help.
Topic closed.