Home Forums Add-ons Repeater Field Front-end forms and repeater fields – only show new entry row


Front-end forms and repeater fields – only show new entry row

  • Hey all!

    I have a front end form working with a repeater. I’m wanting to only allow the user to add a new row, rather than let them edit the previous rows. Is there a solution to this?

  • Hi @speccydan

    The only way I can think to do this would be to add a new text field (similar name to the repeater

    Then add the form to your template but use:
    'fields' => array(), #this is a comma separated list of field keys for each field you need in your form

    Ensure you don’t include the repeater field but instead the new text field!

    When the form is triggered, use the acf/save_post function.

    Within the function, you can then grab the text field and pass the data into the repeater using the add_row function, for example:

    function my_acf_save_post( $post_id ) {
        // Get newly saved values.
        $values = get_fields( $post_id );
        // Check the new value of a specific field.
        $new_text_field = get_field('new_text_field', $post_id);
        if( $new_text_field ) {
    		$row = array(
    			'field_5947dbd28c36e' => $new_text_field,
    		add_row('field_5947dbbd8c36d', $row, $post_id);	#change this to your main repeater key ID	
    #acf/save_post action after ACF has saved the $_POST data. This is possible by using a priority greater  than 1.
    add_action('acf/save_post', 'my_acf_save_post', 20);

    It’s a little long winded but not sure how else to do it! Code is purely as a guide, not tested and may need refining!

  • Thanks @jarvis I’ll give this a shot. I did come up with a “solution” but it’s super hacky and vulnerable.

    I wrote some JS to find all completed form elements above the “add row” button, set their attributes to hidden, and updated both display and pointer-events css attributes to none.

    Of course, anyone savvy enough to inspect the code can undo all of this and still modify the data, but it’s unlikely.

    I’ll give your approach a go though as that’s a lot safer! Thank you.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.