-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 } | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed to be able to order the selection so i built this other helper:
https://gist.github.com/4398157