options getting deleted on save

I have a callback function for a field like as below. It’s a repeatable field it works but on every save a field is gets removed. Say if there are 4 repeated fields on save it reduces to 3 and on next save it gets reduces 2. Options are getting saved

public function ggowl_select_post_template_repeater_callback(){
$ggowl_post_types = $this->ggowl_list_of_post_types();//array containing post types
$ggowl_templates = $this->ggowl_template_list_array();//array containing template list

if(array_key_exists(‘ggowl_select_post_template_repeater’,$this->ggowl_admin_options)){
$fields = $this->ggowl_admin_options[‘ggowl_select_post_template_repeater’];
var_dump($fields);
foreach ($fields as $keyvalue => $ind_fields) {
?>
<div class=”ggowl-outerlist” data-repeater-list=”ggowl_admin_options[ggowl_select_post_template_repeater]”>
<div class=”ggowl-grid-area1 ggowl-repeater-item” data-repeater-item>
<div class=”field”>
<div class=”control”>
<div class=”select is-success”>
<select name=”” id=”ggowl_select_post_template_repeater”>
<?php foreach ($ggowl_post_types as $keys => $postname) {
$selected = (isset( $ind_fields[0] ) && $ind_fields[0] === strval($keys) ) ? ‘selected’ : ” ; ?>
<option value=”<?php echo $keys; ?>” <?php echo $selected; ?>> <?php echo $postname; ?></option>
<?php } ?>
</select>
</div></div></div>
<input class=”ggowl-grid-area3 ggowl-delete-button” data-repeater-delete type=”button” value=”Delete”/>

<!– innner repeater –>
<div class=”ggowl-grid-area2 inner-repeater”>
<div data-repeater-list=”template”>
<div data-repeater-item>
<div class=”field”>
<div class=”control”>
<div class=”select is-success”>
<select name=”” id=”ggowl_select_post_template_repeater”>
<?php foreach ($ggowl_templates as $keys => $post_template) {
var_dump($post_template);
$selected = (isset( $ind_fields[‘template’][0][0] ) && $ind_fields[‘template’][0][0] === strval($keys) ) ? ‘selected’ : ” ; ?>
<option value=”<?php echo $keys; ?>” <?php echo $selected; ?>> <?php echo $post_template; ?></option>
<?php } ?>
</select>
</div></div></div>
</div>
</div>
</div>
</div>
</div>

<?php
}
?>
<input data-repeater-create type=”button” value=”Add”/>
<?php
?>
<?php
}else{ echo “second loop is running”;?>
<div class=”ggowl-outerlist” data-repeater-list=”ggowl_admin_options[ggowl_select_post_template_repeater]”>
<div class=”ggowl-grid-area1 ggowl-repeater-item” data-repeater-item>
<div class=”field”>
<div class=”control”>
<div class=”select is-success”>
<select name=”” id=”ggowl_select_post_template_repeater”>
<?php foreach ($ggowl_post_types as $keys => $postname) {
//$selected = (isset( $this->ggowl_admin_options[‘ggowl_select_post_template_repeater’][0] ) && $this->ggowl_admin_options[‘ggowl_select_post_template_0’] === strval($keys) ) ? ‘selected’ : ” ; ?>
<option value=”<?php echo $keys; ?>” > <?php echo $postname; ?></option>
<?php } ?>
</select>
</div></div></div>
<input class=”ggowl-grid-area3 ggowl-delete-button” data-repeater-delete type=”button” value=”Delete”/>

<!– innner repeater –>
<div class=”ggowl-grid-area2 inner-repeater”>
<div data-repeater-list=”template”>
<div data-repeater-item>
<div class=”field”>
<div class=”control”>
<div class=”select is-success”>
<select name=”” id=”ggowl_select_post_template_repeater”>
<?php foreach ($ggowl_templates as $keys => $post_template) {
//$selected = (isset( $this->ggowl_admin_options[‘ggowl_select_post_template_repeater’][0] ) && $this->ggowl_admin_options[‘ggowl_select_post_template_0’] === strval($keys) ) ? ‘selected’ : ” ; ?>
<option value=”<?php echo $keys; ?>” <?php //echo $selected; ?>> <?php echo $post_template; ?></option>
<?php } ?>
</select>
</div></div></div>
</div>
</div>
</div>
</div>
</div>
<input data-repeater-create type=”button” value=”Add”/> <?php
}

}

Read more here:: options getting deleted on save

Leave a Reply

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