Home › Forums › Front-end Issues › Acf_form() Dont allow to edit.
Hi,
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?
Hi @mr-dan
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’];
Hi @mr-dan
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.
Referer return:
http://www.domain.com/old_path/
Request return:
/current_real_path/
url_to_postid the return:
id: 48
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.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.