Plugin Planet

Premium WordPress Plugins

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 auto-set the post title, this tutorial will explain how it’s done.

Here is a list of the shortcodes/fields for which hidden fields may be used to set fixed values. Note that these are all “primary” fields, for future reference.

  • [usp_name]usp-name
  • [usp_url]usp-url
  • [usp_title]usp-title
  • [usp_tags]usp-tags
  • [usp_category]usp-category
  • [usp_taxonomy]usp-taxonomy
  • [usp_content]usp-content
  • [usp_email]usp-email
  • [usp_subject]usp-subject

Additionally, you may specify per-form custom post types using usp-custom-type.

So let’s look at an example. To set a fixed value for the “Name” field:

  1. Exclude the [usp_name] shortcode in the form
  2. Include a hidden field that uses usp-name for the value, like so:

<input name="usp-name" value="My Fixed Name" type="hidden" />

Likewise for any other primary field, you may auto-set a fixed field value by simply including a hidden field anywhere in the form. Here are some tutorials that employ this technique:

Update!

For reference, here are some additional hidden fields that may be used to define custom post types, set 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" />

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" />

Learn more about overriding global settings.

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:

[usp_category cats="1,2,3"]

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 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 1, 2, 3 with the term IDs that you would like to use (note: terms must exist).

Related Info