Support

Account

Home Forums Front-end Issues acf_form() – action when repeater row added or updated Reply To: acf_form() – action when repeater row added or updated

  • You are going to have to compare each row in the old value stored in the repeater against the new input row.

    Unfortunately I do not know the indexes used for new rows on the input, when acf repeaters are submitted the input for a sub field is

    
    $_POST['acf']['field_XXXXX'][$index]['field_YYYYY']
    

    I am unsure of the $index_value and if they are always integers. I think, but I’m not sure, that new rows have a sting index.

    something like this should work in any case

    
    $something_changed = false;
    $old_values = array();
    if (have_rows('repeater', $post_id) {
      while (have_rows('repeater', $post_id) {
        the_row();
        $old_values[] = get_sub_field('sub_field');
      }
    }
    $new_values = array();
    if (!empty($_POST['acf']['field_XXXXX'])) {
      // loop over input rows
      foreach ($_POST['acf']['field_XXXXX'] as $row) {
        // get sub field value from row
        $new_values[] = $row['field_YYYYY'];
      }
    }
    if (count($old_values) != count($new_values) {
      $something_changed = true;
    } else {
      for ($i=0; $i<count($old_value)l $i++) {
        if ($new_values[$i] != $old_values[$i]) {
          $something_changed = true;
        }
      }
    }
    if ($something_changed) {
       // do something
    }