Home Forums Front-end Issues Acf_form() Dont allow to edit.


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:, After that, you can use the $_POST variable to get the data. This page should give you more idea about it:

    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:

    Request return:

    url_to_postid the return:
    id: 48
    id: 115 (correct)

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.