Hi Elliot,
Voila! That was a very good catch. I hope this thread will be useful to others looking for similar solution and I guess this will be helpful to you too while integrating Frontend forms for ACF 5.xx.
Thanks once again.
Here is my HTML markup:
<form id="post" class="acf-form" action="" method="post" >
<div style="display:none">
<script type="text/javascript">
acf.o.post_id = "new";
</script>
<input type="hidden" name="acf_nonce" value="4ceed66667" />
<input type="hidden" name="post_id" value="new" />
<input type="hidden" name="return" value="http://localhost:8888/product/submit-product?updated=true" />
<div id="wp-acf_settings-wrap" class="wp-core-ui wp-editor-wrap tmce-active">
<div id="wp-acf_settings-editor-tools" class="wp-editor-tools hide-if-no-js">
<a id="acf_settings-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">Text</a>
<a id="acf_settings-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">Visual</a>
<div id="wp-acf_settings-media-buttons" class="wp-media-buttons"><a href="#" id="insert-media-button" class="button insert-media add_media" data-editor="acf_settings" title="Add Media"><span class="wp-media-buttons-icon"></span> Add Media</a></div>
</div>
<div id="wp-acf_settings-editor-container" class="wp-editor-container"><textarea class="wp-editor-area" rows="20" cols="40" name="acf_settings" id="acf_settings"></textarea></div>
</div>
</div>
<div id="poststuff">
<div id="titlediv">
<div id="titlewrap"><label class="screen-reader-text" id="title-prompt-text" for="title">Enter title here</label><input type="text" name="post_title" size="30" id="title" placeholder="Enter product title here" autocomplete="off"></div>
</div>
<div id="wp-frontendform-wrap" class="wp-core-ui wp-editor-wrap html-active">......
</div>
<div id="acf_75" class="postbox acf_postbox default">......
</div>
<div><input type="hidden" name="post_type" value="products" /></div>
<!-- Submit -->
<div class="field">
<input type="submit" value="Submit" />
</div>
<!-- / Submit -->
</div>
<!-- <div id="poststuff"> -->
</form>
The html_after field is <div><input type="hidden" name="post_type" value="products" /></div>
Thanks.
Hi Elliot,
There is no error in the source except
<script type='text/javascript'>
/* <![CDATA[ */
var pluploadL10n = {"queue_limit_exceeded":"You have attempted to queue too many files.","file_exceeds_size_limit":"%s exceeds the maximum upload size for this site."........
.
Hi Elliot,
This is weird. If I set the 'html_after_fields' => '<input type="hidden" name="post_type" value="products">
then it does not invoke the filter acf/pre_save_post
. When it is set to empty, it calls the filter properly. Do you have any insights?
Thanks.
Ok. Here is the debug output:
array(
'acf_nonce' => '665cc6ffdb',
'post_id' => 'new',
'return' => 'http://localhost:8888/product/submit-product?updated=true',
'acf_settings' => '',
'post_title' => 'New Product',
'post_content' => 'New Product details',
'fields' => array(
'field_52031e65653cf' => '',
'field_518d9f7991091' => '091212',
'field_518d9fc591092' => 'product code',
'field_51f73964fdb53' => array(
'acfcloneindex' => array(
'field_51f739d9f6a6f' => '',
) ,
) ,
'field_518da07f91094' => '20131101',
'field_518da16d91095' => '',
'field_52004906dffcf' => '',
'field_52004987277d6' => '',
'field_52478ebfe8454' => '110',
'field_518da32f9109e' => '',
'field_51f729f36ecb8' => '',
'field_518da18491096' => '',
'field_51f7289e80bf1' => '',
'field_51fe885be483c' => '',
'field_518da25691098' => '',
'field_518da2af9109a' => '',
'field_518da2f89109c' => '',
'field_51f73aef05ebf' => '',
'field_51f895a192c59' => '',
'field_51f8968188c4f' => '',
'field_518da51759987' => '',
'field_51fee9fe9fcb5' => '',
'field_51feea629fcb6' => '',
'field_51feea779fcb7' => '',
'field_520f04f1c58d1' => '',
) ,
'post_type' => 'products',
)
Now I am wondering what’s going wrong. Because it seems the post_type is being set properly. Let me debug some more.
Thanks.
I did a var dump of $_POST like so:
$post_type = $_POST['post_type'];
echo 'post type: ' . $post_type . '<br/>';
echo "<pre>";
var_dump($_POST);
echo "</pre>";
exit();
but it seems it never reaches here and throws a 404. The only thing that causes this problem is the hidden field. I have the plugin Debug Objects but am not sure how to catch the error here. A little advice would definitely help me debug and tell you the output.
Hi Elliot,
Did you get a chance to look at this post?
Hi Elliot,
I have set 'html_after_fields' => '<input type="hidden" name="post_type" value="products">'
in the form to the options array. In the functions.php, I have $post_type = $_POST['post_type'];
to reuse the same form for posting different post types.
But this is breaking and after submission, it redirects to 404. I think this is because the hidden field is nested inside <div id="poststuff">
.
Is there any way I can move it outside the poststuff div?
I tried looking at the source in api.php but did not find any way to directly set the post type into the $options array. I think it would be great to have an option to set post_type in the options array and if it is not set, then default it to “post”.
Thanks.
Resolved by using ob_start() and ob_get_clean().
ob_start();
wp_editor( $content, 'frontendform', $settings );
$editor_contents = ob_get_clean();
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.