Home › Forums › ACF PRO › Can\'t get the name value to use $_POST › Reply To: Can\'t get the name value to use $_POST
I’ll try. But I’m repeating my self here. But maybe this will clarify.
This is my ACF form:
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'db_test',
'post_status' => 'publish'
),
'submit_value' => 'Create a new event',
// 'return' => '/wp-content/themes/MY_THEME/includes/new-employee.php'
)); ?>
<?php endwhile; ?>
</div>
</div>
It gives me this HTML
<form id="acf-form" class="acf-form" action="" method="post">
<div class="acf-fields acf-form-fields -top">
<div id="Firstname" class="acf-field acf-field-text acf-field-5968834df2ac1 voornaam" style="width:40%;" data-name="voornaam" data-type="text" data-key="field_5968834df2ac1" data-width="40">
<div class="acf-label">
<label for="acf-field_5968834df2ac1">Voornaam</label>
</div>
<div class="acf-input">
<div class="acf-input-wrap"><input type="text" id="acf-field_5968834df2ac1" class="" name="acf[field_5968834df2ac1]" value="" placeholder="" /></div> </div>
</div>
</div>
<div class="acf-form-submit">
<input type="submit" class="acf-button button button-primary button-large" value="Create a new event" /> <span class="acf-spinner"></span>
</div>
</form>
All I want is when you click on submit it writes the entry to the WP database and returns the value of this acf[field_5968834df2ac1]
field using an echo.
Im trying to do that using this code:
<?php
$FirstName = $_POST['acf']['field_5968834df2ac1'];
echo 'data' . $FirstName; ?>
But that doesn’t give me any results. So my question was/is how do I get the value of this field when I clicked on submit and the page reloads.
Here is my whole code:
<?php acf_form_head(); ?>
<?php /* Template name: Nieuwe Collega's */ get_header(); ?>
<?php session_start();
$_SESSION['foo'] = $_POST['acf']['field_5968834df2ac1'];
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'db_test',
'post_status' => 'publish'
),
'submit_value' => 'Create a new event',
// 'return' => '/wp-content/themes/intranetpuur/includes/new-employee.php'
)); ?>
<?php endwhile; ?>
</div>
</div>
<?php
$FirstName = $_POST['acf']['field_5968834df2ac1'];
echo 'data' . $FirstName;
echo $_SESSION['foo'];
?>
<?php get_footer(); ?>
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.