form()

Embed a form to add / edit a pod item from within your theme.

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

PARAMETERTYPEDETAILS
$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

OPTIONTYPEDEFAULTDETAILS
fields(array)$paramsFields to show on the form, defaults to all fields
label(string)$labelSave button label, defaults to “Save Changes”
thank_you(string)$thank_youThank you URL to send to upon success
fields_only(boolean)falseWhether to only show the form fields which will not output the form submit button.
output_type(string)divThe 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.

Other Helpful Documentation on pods()

add_to()

Add an item to the values of a relationship field.

add()

Add an item to a Pod.

data()

Return an array of all rows returned from a find() call.

delete()

Delete an item from the Pod.

display()

Return the output for a field.

do_magic_tags()

Replace magic tags with their values.

duplicate()

Duplicate an item.

exists()

Whether a Pod item exists or not when using fetch() or construct with an ID or slug.

export_data()

Export data from all items.

export()

Export an item’s data.

fetch()

Fetch an item from a Pod.

field()

Return the value for a field.

fields()

Return field array from a Pod, a field’s data, or a field option.

filters()

Output search filters to be used with find().

find()

Find items of a pod.

first_id()

Return the first item ID.

helper()

Run a helper within a Pod Page or WP Template.

id()

Return the item ID.

import()

Import data.

index()

Return the item name.

last_id()

Return the last item ID.

next_id()

Return the next item ID.

nth()

Fetch the nth state.

pagination()

Display the pagination controls.

position()

Fetch the current position in the loop.

prev_id()

Return the previous item ID.

raw()

Return the raw output for a field.

remove_from()

Remove values from fields.

reset_pod()

Delete all items from the Pod.

reset()

Reset the item position back to the start of the find() list.

row()

Return row array for an item.

save()

Save an item.

template()

Display the page template.

total_found()

Fetch to total number of rows found.

total()

Fetch the total row count.

valid()

Pod object validity.

zebra()

Fetch the zebra switch.