Support

Account

Home Forums ACF PRO ACF front end insert in repeater Reply To: ACF front end insert in repeater

  • Hi @sebastianbotez

    You can’t run a php function in an onclick parameter on a button. That’s for javascript only. So you’ll either have to trigger a javascript function with the onclick parameter which in term does some AJAX in order for you to do the necessary php OR you’ll have to submit the form and let the function run if a POST parameter is set:

    
    
    <?php
    	
    if ( isset( $_POST['submit-playlist'] ) ) {
    
    	//Do your submit code in here
    	
    	$queried_object = get_queried_object();
    	$id = $queried_object->ID;
    	$name = $queried_object->post_title;
    	$poster = get_the_post_thumbnail($id);
    	$permalink = get_the_permalink($id);
    
    	$field_key = "field_558aaa2515415";
    	$user_ID = get_current_user_id();
    	$value[] = array("field_558ab367b4756" => "Playlistul meu", "field_558aaa626db89" => array("field_558ab1d98bcfe" => $permalink));
    	update_field( $field_key, $value, 'user_'.$user_ID );
    }
    
    ?>
    
    <form method="post">
    	<?php if ( isset( $_POST['submit-playlist'] ) ): ?>
    		<p>Thank you, your playlist has been submitted.</p>
    	<?php endif; ?>
    	<input type="hidden" value="<?php sanitize_text_field('submit-playlist'); ?>" name="submit-playlist" />
         <ul>
              <li>
                   <button type="submit" ><img src="<?php echo get_template_directory_uri(); ?>/images/playlist-icon.png" alt="">Playlist</button>
              </li>
         </ul>
    </form>