Home › Forums › Front-end Issues › Acf_form() Dont allow to edit.
ok, I want a form in a regular page (cpt), set a field as hidden, set the current page_id as value, and dont let the user change the value.
But you can always change the val i code on page.
Been trying everything, it works when i use static numbers, but I cant seem to get current page id to save programmaticly without findind a way so the user cant change value in code.
Its because i want to save current page id as a relation to in new created page with page link.
Is the only way to set like $_SESSION value and then when saving fetch it?
I believe you can add a hidden input file using the “html_after_fields” option. These pages should give you more idea about it: https://www.advancedcustomfields.com/resources/acf_form/, http://www.w3schools.com/TAGs/att_input_type.asp. After that, you can use the $_POST variable to get the data. This page should give you more idea about it: http://php.net/manual/en/reserved.variables.post.php.
I hope this helps 🙂
Hi, @acf-support thanx for quick answer.
Thats what I’ve done, but u can always edit values in html code, I need to set the ID in code, not from hidden input field, because you can always change value=”old” to value=”new”.
Somehow i need to get the page_id from the page that has acf_form included in it, and user cant be able to change it.
Well, if any one finds a better way to do this, let us know here.
My solution to the problem:
* Start session on the page with included form in it.
* Set $_SESSION variable data with get_the_ID().
* In acf/pre_save_post start session, and sett field val with Session data.
ie. $_POST[‘acf’][‘field’] = $_SESSION[‘static_page_id’];
I think you can use the HTTP referrer to get the current page URL and then use the url_to_postid() function to convert the URL to the page/post ID. Unfortunately, I haven’t fully tested this method.
Hope this helps 🙂
Thanks @acf-support !
You info let me to use REQUEST_URI instead 🙂
Referer did return the prev url when visiting, or nothing if directly visited.
url_to_postid the return:
id: 115 (correct)
You must be logged in to reply to this topic.
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!
🗓️ Just one more day until the next session of ACF Chat Fridays! Make sure to register for the latest updates on what’s coming in ACF 6.1!— Advanced Custom Fields (@wp_acf) March 30, 2023
📆 Friday 31st March 3pm UTC
👉 Register here - https://t.co/3UtvQbDwNm pic.twitter.com/7xtEJakeQN
© 2023 Advanced Custom Fields.