Support

Account

Home Forums Front-end Issues Increase/Decrease number field via front end form. Reply To: Increase/Decrease number field via front end form.

  • im just straggling same issue like you have. finally I figure it out and im sharing with you. some times you have to separate issue what we need
    1) update field and 2) increase decrease numbers with php.
    lets get started im 100 percent sure you already checked Update_field() documentation
    so in the samples

    
    // Get the current value.
    $count = (int) get_field('my_number_field');
    
    // Increase it.
    $count += 1;
    
    // Update with new value.
    update_field('views', $count);

    if you add this code the page you working and if you use your own CF name every page refresh number will be decrease also if you replace the $count with ( -= 1; ) now every page refresh value will be decrees so step one Is in the pocket πŸ™‚

    next step we need a simple php form to do that action by click

    
    <?php
    $count = (int) get_field('my_number_field'); //first we need our field value 
    if(isset($_POST['increase'])){ // increase 1 if clicked 
       $count += 1;
    }
    
    if(isset($_POST['decrease'])){ // decrease 1 if clicked
       $count -= 1;                                            
    }
    ?>
    
    <form method='post' action='#'> <!-- after click stay in this page -- >
       <td>
           <button name='increase'>+</button>
    <input type='text' size='1' name='item' value='<?= $count; ?>'/> <!-- its will be shows you current value or you change manually   -- >
           <button name='decrease'>-</button>
       </td>
    </form>
    

    couple days ago I just asked a question about changing value with QR code I just figure that one too while im helping you πŸ˜€