Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have two forms. One for adding, one for deleting option values. Deleting and adding works, but I have to manualy reload page to see changes in select part. How to make theme apper after submit?

    <form method="post" action="">
      <input type="text" name="add" class="foo-add" />
      <input type="submit" value="Add" />
    </form>

    <form method="post" action="" name="foo-delete">
        <select multiple="multiple" name="foo-values">
        <?php
        $foo_values = unserialize( get_option( 'foo_values' ));
        $foo_values_keys = array_keys($foo_values);
        $i = 0;
        foreach($foo_values as $foo): ?>
          <option value="foo_<?php echo $foo_values_keys[$i]; ?>"><?php echo $foo[0]; ?></option>
          <?php $i++; ?>
        <?php endforeach; ?>
        </select>
        <input type="submit" value="Delete" />
    </form>        
    </div>
    <?php   
      if($_POST) {
        if(isset($_POST['foo-values'])) {
          preg_match('/\d/', $_POST['foo-values'], $foo_id);
          unset($foo_values[$foo_id[0]]);
          update_option( 'foo_values', serialize($foo_values));
        } else {
          array_push($foo_values, $_POST['foo-add']);
          update_option( 'foo_values', serialize($foo_values));
        }
      }
    ?>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Put the PHP code that handles data at the very top of the page before you print that data.

share|improve this answer
    
I tried header reload but wordpress dosen't allow for this and rise an error –  stamp Oct 16 '12 at 11:39
    
Second method works, thx –  stamp Oct 16 '12 at 11:51
    
Yes, silly me. Header redirects fail if output precedes them. Edited the post to reflect this. Glad the other way solved it. –  Calle Oct 17 '12 at 0:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.