Skip to content

Instantly share code, notes, and snippets.

@benfavre
Forked from anonymous/gravityforms.php
Last active December 10, 2015 05:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfavre/4390827 to your computer and use it in GitHub Desktop.
Save benfavre/4390827 to your computer and use it in GitHub Desktop.
Pods 2.0 Gravity Forms input helper. Use a text or code field.
<?php
wp_enqueue_style( 'pods-select2' );
wp_enqueue_script( 'pods-select2' );
$attributes = array();
$attributes[ 'tabindex' ] = 2;
$pick_limit = (int) pods_var( 'pick_limit', $options, 0 );
$name .= '[]';
$attributes[ 'multiple' ] = 'multiple';
if ( !is_array( $options[ 'data' ] ) && false !== $options[ 'data' ] && 0 < strlen( $options[ 'data' ] ) )
$options[ 'data' ] = implode( ',', $options[ 'data' ] );
else
$options[ 'data' ] = (array) pods_var_raw( 'data', $options, array(), null, true );
$attributes = PodsForm::merge_attributes( $attributes, $name, PodsForm::$field_type, $options );
if( class_exists( 'RGFormsModel' ) )
{
$forms = RGFormsModel::get_forms(1, "title");
if( count( $forms ) > 0 )
{ ?>
<div class="pods-select2">
<select<?php PodsForm::attributes( $attributes, $name, PodsForm::$field_type, $options ); ?> style="width:95%;">
<?php
foreach( $forms as $form ) :
$selected = '';
if ( $form->id == $value || ( is_array( $value ) && in_array( $form->id, $value ) ) )
$selected = ' SELECTED';
if ( is_array( $option_value ) ) {
?>
<option<?php PodsForm::attributes( $form->id, $name, PodsForm::$field_type . '_option', $options ); ?>><?php echo $form->title; ?></option>
<?php
}
else {
?>
<option value="<?php echo $form->id; ?>"<?php echo $selected; ?>><?php echo $form->title; ?></option>
<?php
}
endforeach ?>
</select>
</div>
<script type="text/javascript">
jQuery( function ( $ ) {
var $element = $('#<?php echo $attributes[ 'id' ] ?>' );
$element.select2({
placeholder: "Choisir un ou plusieurs formulaire"
});
});
</script>
<?php }
else
{ ?>
<p>There are no forms available at this time. You may <a href="admin.php?page=gf_new_form">create one</a> now (<strong>warning</strong> entered data <em>will be lost</em> unless you save first)</p>
<?php }
}
else
{ ?>
<p>Gravity Forms is currently not available.</p>
<?php }
?>
@BrookeDot
Copy link

This looks super helpful. I'm just new to PODS where is the best place to put it?

@benfavre
Copy link
Author

You need to enable the "Helpers" component.
Then add this code as an input helper and give it a name.
Then add a field and choose "Code (Syntax Highlighting)" as the field type and in the advanced tab choose the helper you created in the "Input Helper" dropdown.

@benfavre
Copy link
Author

I needed to be able to order the selection so i built this other helper:
https://gist.github.com/4398157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment