Hello,
We need to create RIB field. Concat of 4 fields. So, we use prepopulate_field_setting to get labels fields.
I miss something, I don't see 4 field by js.php by one alone.
When i save, the fields are note recorded.
I think there is an array or something else to describe my fields but i don't see how?
Could you help me?
Thank you,
Justin.
our code:
<?php
/*
http://wpsmith.net/2011/plugins/how-to-create-a-custom-form-field-in-gravity-forms-with-a-terms-of-service-form-field-example/
*/
global $rib_fields;
$rib_fields = array(
array(
'title'=>'Code établissement',
'size'=>'5',
'label'=>'bank_code',
),
array(
'title'=>'Code guichet',
'size'=>'5',
'label'=>'sort_code',
),
array(
'title'=>'Numéro de compte',
'size'=>'11',
'label'=>'account_number',
),
array(
'title'=>'Clé RIB',
'size'=>'2',
'label'=>'key',
),
);
class gravityforms_fields_addons {
public function __construct($master) {
$this->master = $master;
}
public function init() {
// Add a custom field button to the advanced to the field editor
add_filter( 'gform_add_field_buttons', 'wps_add_rib_field' );
function wps_add_rib_field( $field_groups ) {
foreach( $field_groups as &$group ){
if( $group["name"] == "advanced_fields" ){ // to add to the Advanced Fields
//if( $group["name"] == "standard_fields" ){ // to add to the Standard Fields
//if( $group["name"] == "post_fields" ){ // to add to the Standard Fields
$group["fields"][] = array(
"class"=>"button",
"value" => __("RIB", "gravityforms"),
"onclick" => "StartAddField('rib');"
);
break;
}
}
return $field_groups;
}
// Adds title to GF custom field
add_filter( 'gform_field_type_title' , 'wps_rib_title' );
function wps_rib_title( $type ) {
if ( $type == 'rib' )
return __( 'RIB' , 'gravityforms' );
}
// Adds the input area to the external side
add_action( "gform_field_input" , "wps_rib_field_input", 10, 5 );
function wps_rib_field_input ( $input, $field, $value, $lead_id, $form_id ){
global $rib_fields;
if ( $field["type"] == "rib" ) {
$max_chars = "";
if(!IS_ADMIN && !empty($field["maxLength"]) && is_numeric($field["maxLength"]))
$max_chars = self::get_counter_script($form_id, $field_id, $field["maxLength"]);
$input_name = $form_id .'_' . $field["id"];
$tabindex = GFCommon::get_tabindex();
$css = isset( $field['cssClass'] ) ? $field['cssClass'] : '';
$output = "<div class='ginput_container'>";
foreach($rib_fields as $idx => $f) {
$output .= sprintf("<span style='float: left; padding-right: 20px;'><label style='display: block;'>%s</label><input name='input_%s' id='%s' class='input gform_rib %s' $tabindex size='%s' maxlength='%s' value='%s'></span>{$max_chars}", $f['title'], $field["id"].".".$idx, 'input_'.$field['id'].'_'.$idx, $field["type"] . ' ' . esc_attr( $css ), $f['size'] + 1,$f['size'], esc_html($value));
}
$output .= "</div>";
return $output;
}
return $input;
}
// Now we execute some javascript technicalitites for the field to load correctly
add_action( "gform_editor_js", "wps_gform_editor_js" );
function wps_gform_editor_js(){
?>
<script type='text/javascript'>
jQuery(document).ready(function($) {
fieldSettings["rib"] = ".label_setting, .description_setting, .admin_label_setting, .size_setting, .error_message_setting, .css_class_setting, .visibility_setting, .rib_setting, .prepopulate_field_setting";
//binding to the load field settings event to initialize the checkbox
$(document).bind("gform_load_field_settings", function(event, field, form){
jQuery("#field_rib").attr("checked", field["field_rib"] == true);
$("#field_rib_value").val(field["rib"]);
});
});
</script>
<?php
}
// Add a custom setting to the tos advanced field
add_action( "gform_field_advanced_settings" , "wps_rib_settings" , 10, 2 );
function wps_rib_settings( $position, $form_id ){
// Create settings on position 50 (right after Field Label)
if( $position == 50 ){
}
}
}
}
?>