This tutorial explains how to use hidden fields to set values for form fields. For example, if you have a form for which you would like to specify a fixed Post Title, you can do so by making the field a hidden input.
Primary form fields
Here is a list of the primary shortcodes/fields that may be hidden to define fixed values:
For each of these fields, there are two ways to make it a hidden field.
Hide field via shortcode attribute
To hide any of the primary fields listed above, add the
custom attribute to its shortcode. For example, here we are hiding the Name field:
[usp_name label="null" placeholder="null" fieldset="null" custom="style='display:none;'"]
Note that we also include attributes to remove the
fieldset by setting their values to
null. These attributes/tags are not required for hidden inputs.
When would you want to hide a field via this method? When you want the form to auto-fill the value when the user is logged in, which only works for the Name and Email fields.
Hide field via direct input markup
It’s also possible to include hidden fields directly in the form. So instead of using the shortcode, we can add a hidden Name field like so:
<input name="usp-name" value="My Fixed Name" type="hidden">
The key to this method is the value of the
name, which in this example is
usp-name. To hide other primary fields, refer to the list provided at the beginning of this article. There you will find the proper
name value to use for each shortcode/field.
When would you want to hide a field using this method? When you want to define a fixed value for the field, such that it can’t be changed by the user or the plugin.
Hide custom fields
What about custom fields? Yep, you can hide those too. Custom fields (added via the
[usp_custom_field] shortcode) can be hidden by adding
type attributes. For example, here are hiding the Name field:
Notice also that we disable the field
fieldset by using
null as their respective attribute values. We do this because these attributes/tags are not required for hidden inputs. Examine the source code of your form’s web page for more information.
Hiding other fields
Here are some additional hidden fields that may be used to define custom post types, set custom post formats, and override global settings:
Submit Posts -> <input name="usp-is-post-submit" value="1" type="hidden"> Register Users -> <input name="usp-is-register" value="1" type="hidden"> Send Email -> <input name="usp-is-contact" value="1" type="hidden"> Submit Child Posts -> <input name="usp-post-parent" value="8" type="hidden"> Custom Post Type -> <input name="usp-custom-type" value="book" type="hidden"> Custom Post Format -> <input name="usp-custom-format" value="video" type="hidden"> Custom Contact IDs -> <input name="usp-contact-ids" value="1,3" type="hidden">
Check out the Related Posts below for more things you can customize with hidden fields.
Hidden Fields for Categories
There are two ways to specify categories for submitted posts. First, you can visit General ▸ Category Settings, and check/enable the option to “Hide Category Field”. Then in all of your forms you can just use the category shortcode as usual. For example, to assign categories 1, 2, and 3 to the submitted post, the shortcode looks like this:
The other method of assigning categories to submitted posts is to just add a hidden field, like this:
<input name="usp-cats-default" value="1|2|3" type="hidden">
This second way of doing it is nice because it doesn’t matter if the setting “Hide Category Field” is enabled or not. In fact, if you leave it disabled, you can assign categories AND display the Category field for users to select additonal categories. Good times.
Hidden Fields for Tags
As explained here, you can assign specific tags to all submitted posts using the shortcode, like so:
It’s also possible to assign tags via hidden field, for example:
<input type="hidden" name="usp-tags-default" value="1|2|3">
Just replace the
value attribute with whichever tag IDs you would like to assign to any posts submitted via the form.
Hidden Field for Custom Taxonomy
While not officially supported, it is possible to set taxonomy term IDs using hidden fields. For example:
<input type="hidden" name="usp-taxonomy-people" value="1"> <input type="hidden" name="usp-taxonomy-people" value="2"> <input type="hidden" name="usp-taxonomy-people" value="3">
Here we are specifying three terms from the
people taxonomy, which may be changed to whatever taxonomy name is required. Also change the values
3 with the term IDs that you would like to use (note: the terms must exist).
- USP Pro – Default Post Title and Content
- USP Pro – Unlimited Custom Post Types
- USP Pro – Custom Post Formats
- USP Pro – Submit Child Pages
- USP Pro – Replace Default Post Title
- USP Pro – Assign Specific Categories
- USP Pro – Hide Name and Email Fields for Logged-In Users
- USP Pro – Override Global Registration Settings