How to use pods fields in existing forms of thirdparty themes |

How to use pods fields in existing forms of thirdparty themes

When a developer is using wordpress with in a existing theme that comes with exising forms, there is a work to do if he wants to integrate extended fields into those forms. For example if a theme comes with a registration form and there are several extended fields for the user.

In this case we need to add inside the form the new fields, and this can be a “pain”, because with form methods of pods object the work is done in seconds.

1
2
3
4
5
6
7
$mypod = pods( 'mypod' );

// Only show the 'name', 'description', and 'other' fields.
$fields = ( 'name', 'description', 'other' );

// Output a form with all fields
echo $mypod->form($fields);

We can’t use this becase form method render an entire form with its

1
"
1
 

tag and with the submit button.

Well, to do this we can use directly the function field from PodsForm.php (http://pods.io/docs/code/pods-form/field/). I leave you a function donde by me:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function pods_utils_show_pod_fields($pod, $selected_fields = null, $name_prefix = "", $theme_name = ""){
$pods = pods( $pod );
$fields = $pods->fields();
foreach($fields as $field) {
if($selected_fields != null)
if(!($field['name'], $selected_fields))
continue;
?>
<label for="&lt;?php echo  $name_prefix . $field['name']; ?&gt;">
<!--?php _e( $field['label'], $theme_name ); ?-->
<!--?php $label['options']['required'] == 1 ? _e( '(required)', $theme_name ) : ""; ?-->
</label>
<!--?php echo PodsForm::field( $name_prefix . $field['name'], null, $field['type'], null, $pod_name, null ); ?-->
<!--?php <br ?--> }
}

pods_utils_show_pod_fields('mypod');

pods_utils_show_pod_fields('mypod', ("field1", "field3"));

Hope it helps

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>