フォームの作成
form
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 )
パラメータ
$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
戻り値
(bool|mixed)
Examples
コード例
<?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.