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 |
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.