Home › Forums › ACF PRO › ACF front end insert in repeater › Reply To: ACF front end insert in repeater
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>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.