Embed a form to add / edit a pod item from within your theme. Provide an array of $fields to include and override options where needed. For WP object based Pods, you can pass through the WP object field names too, such as “post_title” or “post_content” for example.
Function Definition
public function form ( $params = null, $label = null, $thank_you = null )
Source File: /pods/classes/Pods.php
Since: 2.0
Parameters
| PARAMETER | TYPE | DETAILS |
|---|---|---|
| $params | (array) | (optional) Fields to show on the form, defaults to all fields |
| $label | (string) | (optional) Save button label, defaults to “Save Changes” |
| $thank_you | (string) | (optional) Thank you URL to send to upon success |
Additional Parameter Options
| OPTION | TYPE | DEFAULT | DETAILS |
|---|---|---|---|
| fields | (array) | $params | Fields to show on the form, defaults to all fields |
| label | (string) | $label | Save button label, defaults to “Save Changes” |
| thank_you | (string) | $thank_you | Thank you URL to send to upon success |
| fields_only | (boolean) | false | Whether to only show the form fields which will not output the form submit button. |
| output_type | (string) | div | The output type to use when rendering the form labels and fields. Available options are: div, p, ul, table |
| check_access | (boolean) | true | Whether to check access rights of the current user before allowing the form to display. |
| form_key | (string) | null | Additional context to pass to the access rights logic to better identify the specific form. This would allow you to customize your access rights overrides by targeting specific a form key. This ends up being used as the “context” parameter passed into the hooks pods_user_can_access_object_get_capabilities, pods_user_can_access_object_pre_check, amd pods_user_can_access_object. |
Returns
(string) The form output.
Examples
Example 1
<?php $mypod = pods( 'mypod' ); // Output a form with all fields echo $mypod->form(); // Only show the 'name', 'description', and 'other' fields. $fields = array( 'name', 'description', 'other' ); // Override the options of a specific field $fields = array( 'name', 'description' => array( 'type' => 'paragraph', 'label' => 'Special Label' ), 'other' ); //set default value for fields $params = array( 'lightsaber_color' => array( 'default' => 'green' ) , array( 'sith_or_jedi'=> array( 'default' => 'jedi' ) ) ); echo $mypod->form( $params ); // Output a form with specific fields echo $mypod->form( $fields ); // Edit an item (shorthand) $mypod = pods( 'mypod', $id ); // Output an edit form with all fields echo $mypod->form(); // Edit an item (shorthand) echo pods( 'mypod', $id )->form(); // Output a form with specific fields, custom label, and thank you URL // (with ID passed into it) echo $mypod->form( $fields, 'Submit', '/thank-you-for-submitting/?new_id=X_ID_X' );
Output fields only, without submit.
This functionality was added in Pods 2.3.19
<?php
$pods = pods( 'jedi' );
$params = array( 'fields_only' => true, 'fields' => array('side_of_force', 'lightsaber_color') );
echo $pods->form( $params );
The above example will output:
HTML for form fields for 'side_of_force' and 'light_saber_color' without the rest of the HTML for the form or submit.