Forms Shortcodes

Besides the shortcodes of the list, there are special shortcodes that control the basic functionality of every form:

  • [credform][/credform]: renders a post form
  • [creduserform][/creduserform]: renders a user form
  • [cred_field field='form_messages']: renders the message containers
  • [cred_field field='form_submit' value='Submit']: renders the submit button

Warning: removing the mandatory shortcodes from your forms will cause them to break.

cred_delete_post_link

Description

Displays a link to delete a post

Arguments
  • post. Optional. The ID of post to delete. If skipped, the ID of the current post in the loop will be used.

  • text. Optional. The text to use for link (can use placeholders like %TITLE% and %ID%)

  • action. Optional. Whether to trash or permanently delete. Can take values: trash and delete.

  • class. Optional. CSS class to apply to the link.

  • style. Optional. CSS style to apply to the link.

  • message. Optional. The confirmation message before deleting the post.

  • message_after. Optional. The confirmation message after deleting the post.

  • message_show. Optional. Whether or not to show confirmation message before deleted. Can take values: 1 or 0.

  • redirect. Optional. A post ID to redirect the user after deleting the post. If set to 0, then the user will not being redirected.

Output

More Usage examples

Example
//Display link for deleting car custom post with ID 145:
[cred_delete_post_link post="145" text="Delete this car" action="delete"]

//The function can also be used in PHP:
//Note that you have to echo this function in order to work properly.
The order of arguments in the function is important and should be as following:
cred_delete_post_link($post_id, $text, $action, $class, $style, $message, $message_after, $message_show, $redirect);

//Fully working example of the function:
echo cred_delete_post_link(get_the_ID(), 'Delete this post', 'delete', 'cred-refresh-after-delete my-custom-css-class', 'display: block;', 'Do you really want to delete this post?', 'Post Deleted.', 1, 1);

//Change the URL that users will be redirected to after deleting a form.
add_filter("cred_redirect_after_delete_action", "test");
function test($redurl, $post_id) { 
    return "/client/"; 
}

cred_field

Description
Render a form field (using fields defined in Toolset Types plugin and / or Taxonomies).
Arguments
  • field. The field slug.
  • post. Optional. The Post Type where this field is defined.
  • value. Optional. Preset value (translated automatically if WPML translation exists). Must match the expected Field's syntax. For example, date fields require a valid timestamp instead of a date string. Does not apply to all field types, e.g. taxonomies.
  • taxonomy. Optional. Used by taxonomy auxiliary fields (eg. “show_popular”) to signify to which taxonomy this field belongs (used with “type” option).
  • type. Optional. Used by taxonomy auxiliary fields (like show_popular) to signify which type of functionality it provides (eg. “show_popular”) (used with “taxonomy” option).
  • display. Optional. Used by fields for Hierarchical Taxonomies (like Categories) to signify the mode of display (ie. “select” or “checkbox”).
  • single_select. Optional. Boolean. If the display=select argument is set, then single_select=true will only allow a single option to be selected (by default multiple options can be selected). Defaults to false.
  • readonly. Optional. Boolean. When set to true, the field will be read only. Read-only parameter can be applied only to text controls and not to other elements, like checkboxes or buttons. Defaults to false.
  • placeholder. Optional. Text to be used as a placeholder (HTML5) for text fields. Defaults to none.
  • urlparam. Optional. A URL parameter to set default value. For example, a URL with the additional parameter ?some_param=some_value will set the some_value value to some_param.
  • output. Optional. If set to bootstrap, the form elements will get the styling from bootstrap framework. Otherwise, raw elements output will be rendered.
  • class. Optional. CSS class to apply to the link.
  • single_select Optional. Used by fields for Hierarchical Taxonomies (like Categories) to signify that the select field does not support multi-select mode.
  • max_width Optional. Maximum width for image fields.
  • max_height Optional. Maximum height for image fields.
  • max_results Optional. Maximum results in parent select field.
  • use_select2 Optional. Used in parent select fields. Options are always and never. It will render the parent select field as a Select2 field or not, depending on the value set. Works only on sites not using the new post relationships (legacy code). If used with new post relationships (Types 3,0+), it breaks the "order", "ordering" and "author" attributes. It can also break background checks like what post type to display in the select field for relationships. Warning: Do not use this attribute if not explicitly required.
  • order Optional. Order for parent select field (title or date).
  • ordering Optional. Ordering for parent select field (i.e. "asc", "desc").
  • required Optional. Select whether parent field is required. Defaults to false
  • no_parent_text Optional. Text for no parent selection in parent field.
  • select_text Optional. Text for required parent selection.
  • validate_text Optional. Text for the error message displayed when parent is not selected.
  • author Optional. Use it with a parent selector field to specify that the list of parent posts should be limited to those authored by the mentioned user ID. The value $current can be used to define that the current user should only see their own parent posts in a dropdown.
Output

More Usage examples

Example
//Render the Mobile Types field defined for Agent post type
[cred_field field="mobile" post="agent" value="555-1234"]
// List parent posts limited to those authored by the current user.
[cred_field field='@relationship-slug.parent' select_text='--- not set ---' class='form-control' output='bootstrap' author="$current"]

cred_form

Description
Arguments
  • form. The form title or form ID to display.

  • name. The name of the form to display.

  • post. Optional. The post ID to edit with this form. If form is an edit form and this is skipped, the ID of the current post in the loop will be used.

Output

More Usage examples

Example
//Display form for editing car custom post with ID 145 (use form with title “Edit Car”)
[cred_form form="Edit Car" post="145"]

//Display form to create a car post (use form with title “Create Car”)
[cred_form form="Create Car"]

//Display form with ID 120
[cred_form form="120"]

//The corresponding PHP function can also be used:
cred_form($form_id,$post_id);

cred_generic_field

Description

Render a form generic field (general fields not associated with Toolset Types plugin). Inside shortcode body the necessary options and default values are defined as JSON string (autogenerated by GUI).

Arguments
  • field. The field name.

  • type. Type of input field (i.e. checkbox, checkboxes, date, hidden, radio, select, multiselect, file, image, email, numeric, integer, embed, url, skype, phone, password, textfield, textarea, wysiwyg, audio, video, colorpicker).

  • class. Optional. CSS class to apply to the element.

  • urlparam. Optional. A URL parameter to set default value. For example, a URL with the additional parameter ?some_param=some_value will set the some_value value to some_param.

Output

More Usage examples

Example
// basic generic email field
[cred_generic_field field="gmail" type="email" class=""]
 {
  "required":0,
  "validate_format":0,
  "default":""
 }
[/cred_generic_field]


// generic user id field for automatic email notifications
[cred_generic_field field="wpcf-user" type="select" class="" urlparam=""]
 {
  "generic_type" : "user_id",
  "required" : 1,
  "validate_format" : 0,
  "persist" : 1,
  "default" : 12,
  "options" : [
    {"value":"user1","label":"User1"},
    {"value":"user2","label":"User2"},
    {"value":"user3","label":"User3"}
  ]
 }
[/cred_generic_field]

cred_user_form

Description
Arguments
  • form. The form title or form ID to display.

  • user. Optional. The ID of the user to edit. If skipeed, the current logged in user will be used.

Output

More Usage examples

Example
//Display form for editing user with ID 23 (use form with title “Edit User”)
[cred_user_form form="Edit User" user="23"]

//Display form for editing current logged in user (use form with title “Edit User”)
[cred_user_form form="Edit User"]

//Display form to create a user (use form with title “Create User”)
[cred_user_form form="Create User"]

//Display form with ID 50
[cred_user_form form="50"]

//The corresponding PHP function can also be used:
cred_user_form($form_id,$user_id);

cred-form-cancel

Description

This shortcode renders a Cancel button in a relationship form and offers a way out of creating or editing a relationship. It also allows you to specify where user is taken after cancelling the form submission and which template is used when rendering the page that is shown. Note that this shortcode only works properly on relationship forms, not on the post and user forms. It lets you skip the form and get somewhere else.

Arguments
  • select_ct. Optional. Sets the slug of the Content Template that will be forced upon the page where the link will redirect to. If it is not set, no Content Template will be forced.

  • select_page. Optional. Sets the ID of the post or page where the link will redirect to. If it is not set, the link will reload the current page.

  • class. Optional. For defining additional class names for this selector.

  • style. Optional. For defining additional styles for this selector.

Output

cred-form-feedback

Description

This shortcode renders the form submission feedback. Feedback can be a success message or one of the fail messages. Note that this shortcode works properly only on relationship forms and not on post and user forms.

Output

cred-form-submit

Description

This shortcode submits the form to create or edit a relationship. Note that this shortcode only works properly on relationship forms, not on the post and user forms.

Arguments
  • type. Optional. HTML element to show. It can take as values button or input. Defaults to input if not set.

  • label. Optional. Sets the submit button label. Defaults to Submit if not set.

  • class. Optional. For defining additional class names for this selector.

  • style. Optional. For defining additional styles for this selector.

Output

cred-relationship-field

Description

This shortcode is used for managing relationship fields when they are available. Have in mind that only many-to-many relationships can hold fields. This shortcode takes only one attribute

Arguments
  • name. Mandatory. Sets the slug of the field that this shortcode will offer.

Output

cred-relationship-form-container

Description

This is a wrapper shortcode for the relationship forms that encapsulates the whole form. Output of this shortcode wraps form elements with the form HTML tag.

Output

cred-relationship-role

Description

This shortcode displays a selector for the posts that will be connected by the relationship that is being created or edited. Note that this selector is displayed as a select2 instance.

Arguments
  • role. Mandatory. Can take the values of parent or child, to decide what relationship side will this selector offer posts to. As the form settings store the relationship that this form will create or edit, once the role is set the selector will display the right posts for the right post type.

  • orderby. Optional. Can take the values of date, title or ID. ID is the default value. It will decide the order of the posts being offered in this role selector.

  • order. Optional. Can take values of ASC and DESC. DESC is the default value. Defines the direction for the post oreder being offered in this role selector.

  • author. Optional. Can take just one value as $current. It is used to filter the posts offered in this role selector to ones by the current user.

  • class. Optional. For defining additional class names for this selector. Note that this gets applied to the select dropdown behind the select2 instance.

  • style. Optional. For defining additional styles for this selector. Note that this gets applied to the select dropdown behind the select2 instance.

Output

toolset-edit-post-link

Description

Outputs the link to a Toolset Form for editing a post.

This shortcode needs to be self-closed with the anchor (link) text in the middle. The anchor text can use the %%POST_TITLE%% and %%POST_ID%% placeholders to dynamically display the post’s title and ID.

Arguments
  • content_template_slug. Holds the slug value of the Content Template that will be used to render the page when clicking the edit link. Please note that either the content_template_slug or the layout_slug attribute need to be set for the edit link shortcodes to work.

  • layout_slug. Holds the slug value of the layout that will be used to render the page when clicking the edit link. Please note that either the content_template_slug or the layout_slug attribute need to be set for the edit link shortcodes to work.

  • style (opt). Optional. The style of the element. Takes a string value and will be added unchanged to the HTML element

  • target. Optional. Defines the window in which the link will be opened. This can be the current window (self), top window (top), or a new window (blank). Defaults to self.

  • class. Optional. The class of the element. Takes a string value and will be added unchanged to the HTML element

Output

More Usage examples

Example
[toolset-edit-post-link content_template_slug="template-for-editing-posts"]Edit %%POST_TITLE%% with a Toolset Form[/toolset-edit-post-link]