Support

Account

Home Forums Bug Reports Can not save empty text field

Solving

Can not save empty text field

  • I’m using ACF PRO 5.3.7 with WP 4.5.1

    I’ve ran into a problem when editing text field values. I have a CPT with a number of text fields for various data.

    When I try to edit a field value everything works fine. But when trying to empty the field the value jumps back when post is saved.

    The field is a simple text field and it is not a required field.

  • It sounds like you have another field on the same page with the same name.

  • It surely does. But I did check for that. And it’s not that. And I have found the same issue on other sites. I recently moved a lot of sites to a new host and it seems to be a server issue.

    Although, the host thinks it’s a issue with the PHP version, 5.6.19

    Is there any known issues with ACF PRO and PHP version 5.6.19?

  • what is the difference between 5.6.17 and 5.6.19? I don’t think there’d be enough difference to cause a problem, nothing but bug fixes from what I can see and all my sites are running on .17

    The only other thing I can think of is that the field is not being submitted when it’s empty, but that doesn’t make any sense to me since you say you can change it you just can’t save it with no value. TIf the field is a conditional field in ACF, and it is hidden because of the conditions, that would cause ACF not to updated it. If the value is being sent but not updating….. I’m a little lost. The only thing I know of that can cause this is a problem with the PHP input_max_vars setting, but that will just cut off after a number of fields, it’s not selective based in it having a value or not.

    My next step in troubleshooting would be to add this to the top of my functions.php file to see if my empty value is actually getting to the server. That will narrow it down to either a PHP or a JS problem.

    
    echo '<pre>'; print_r($_POST); die;
    

    You’ll need to look for the field key of the field.

  • Thanks for your thoughts.

    Not sure where to put the code or what to expect from it.

    I have a fresh test install using Twentysixteen theme. Put that in on top of the functions.php file (inside the opening tag). All that gives me is a white screen with:

    Array
    (
    )

    I must be doing it wrong. Any hints?

  • Umm, yeah, I guess it’s not that simple and I should have know that. We only want to have it run if there are ACF field being submitted.

    
    add_action('init', 'see_whats_posted');
    function see_whats_posted() {
      if ((!defined('DOING_AJAX') || !DOING_AJAX) && isset($_POST['acf'])) {
        echo '<pre>'; print_r($_POST['acf']); die;
      }
    }
    

    Once this is set up go to the page with the field you can’t set to empty, clear the value and save the post. What this will do is, when you submit a post with ACF fields it will show the values submitted and exit PHP. This will let you see if the empty value in the field is submitted.

  • Ok. Tried this.

    It doesn’t do anything. It doesn’t break my site. It doesn’t return anything.

    This is supposed to happen on the edit-post-screen right?

    Since this is a test site I haven’t included the field to any template. Since it’s a backend issue.

  • Yes, it should do something. When I put that in the functions.php file of my test site it does exactly what I outlined that it should do. If you site isn’t then the functions.php file you put it in is not being loaded. Does your hosting have any type of optcode caching in place? You might want to submit a support ticket https://support.advancedcustomfields.com/new-ticket/

  • I’ve submitted a ticket.

    If interested you can have login details to the site to see for yourself. Let me know where to send it.

  • Ok. Here is something new and maybe helpful!

    When I edit the field to anything not just empty, it returns this:

    Array
    (
    [field_572797d158ec1] => testvalu
    )

    But when I leave it empty and update the post I get the green sign saying “post updated” and the field is filled with its original value.

    So when set to empty nothing is sent? What does that tell us?

  • Actually working on your site is more than I can do for you, that’s what support does. I’m for the most part just another user and I’m limited to helping you here this way.

    When I submit and empty feid it works the same for me, I just get an empty value. You said this is a test site, but do you have any other plugins installed and running besides ACF.

  • Oh, sorry! I thought you were with the ACF team!

    I guess that that is how it’s supposed to work. That you get an empty value. Obviously something is wrong here.

    A test site with only ACF Pro running.

  • I am with the ACF team, sorta, but not beyond this forum.

    So, the question is, why isn’t the empty value being submitted? And is it being stripped before or after the post is being submitted to the server? I don’t know anything in a standard WP installation with just 2016 and ACF Pro that would cause this.

  • Ok. Appreciate your help!

    Nope. It seems like we can confirm that this is a server issue. Hosting doesn’t have a clue though. Still says its a php version issue.

    I don’t know. 5.6.19 has been out for two months. If ACF didn’t run with that version the issue would have been known already, I think.

    I you happen to have a clue what to tell my hosting, please let me know.

    Cheers!

  • Hosting seems to have resolved the issue.

    But they did it by disabling PHP Suhosin. Odd way of “resolving” I think.

    Isn’t Suhosin and ACF compatible??

  • More than likely it is a setting or something in that extension, I don’t know anything about it because my host does not use it. When I was looking for an answer to your problem I did read something about it but nothing I read indicated that it would cause the problem you were having.

  • I am having exactly the same issue as described. I’m on WP4.6.1 and have just installed ACF for the first time. I’ve setup a basic image field and then a text field. When I enter text in to the text field and click Publish, the content is updated fine. When I remove all text from the text field and click Publish, the field seems to retain the last value. This only happens when the field is blank.

    I do not have WP-Cache as true, I have a very basic install. There are no conflicting field names/ids on the page.

    Any idea how I can fix this?

  • There are not problems with this in either ACF4 or 5. This is either a conflict with another plugin, the theme, or possibly something to do with your hosting as was discovered by the OP’er. You can try submitting a ticket https://support.advancedcustomfields.com/new-ticket/ or possibly contacting your host and seeing if they have the PHP Suhosin installed on the server that was mentioned above.

  • Thanks for the info. I was just hoping there might be more info on the actual fix. Suhosin is very configurable so simply disabling is a bit of overkill. I’ll do some more investigating and report back here if/when I find the solution.

  • I’ve disabled suhosin completely and the issue persists. I’ll keep searching for a solution.

  • I’ve checked with Firebug and the post variable is set correctly each time. ie. when I set the text field value as “wookie”, the variable has the value in Firebug, and when I set the text field value as empty/blank, the variable exists but is empty.

  • I don’t know anything about it to be honest. There has to be something that’s preventing the empty fields from being submitted. I did a web search for “php empty fields not submitted” and all I find is stuff on form validation, how to prevent empty fields and this topic. Absolutely nothing on why a field without a value is not being submitted.

    Not sure if this has anything to do with it bu what version of PHP are you using?

    Do other types of fields do the same thing if you remove the value. For example, if you create a select field that only allows one choice and you allow null. Is this field updated when you remove the value?

  • Yeah, it’s strange. I don’t think it’s the plugin but it’s just strange as I’ve not seen it with wordpress before (on this same server). I’m on php 5.6.

    I have tried adding another field, this time a textarea and the same issue.

    I might try disabling other plugins first before going any further.

  • My last update for tonight 🙂

    I have confirmed the values are being posted correctly, however when I do an SQL query log in WordPress, their is no value pair for text field.

    I have just tested the site in php 7.0 and it’s working! There is obviously something going on with PHP/Suhosin/Wordfence/mod_security that is causing the issue but it’s tricky to narrow down.

    I hope my posts helps someone and can save them from hours of frustration!

  • If you’re still around, let’s find out it the value is getting to WP or if the value is being removed before WP is loaded.

    This will require a bit of hacking, but sometimes it’s necessary. You didn’t say, so I am assuming that the field is on a “post” edit screen, if not let me know.

    Step 1) Open the page/post where the field is not submitting the empty value. Make sure the field has a value and save the post. Leave the browser open on this page while you do the next step.

    Step 2) Open the file /wp-admin/post.php, the top of the file should look something like this.

    
    <?php
    /**
     * Edit post administration panel.
     *
     * Manage Post actions: post, edit, delete, etc.
     *
     * @package WordPress
     * @subpackage Administration
     */
    
    /** WordPress Administration Bootstrap */
    

    Just after the opening PHP tag add this

    
    <?php
    echo '<pre>'; print_r($_POST); die;
    
    /** .....
    

    Step 3) Go back to the browser and remove the value from the field and then click update post. You should get see the submitted array of values. Is the field that you are trying to clear there and does it have an empty string as a value?

Viewing 25 posts - 1 through 25 (of 30 total)

The topic ‘Can not save empty text field’ is closed to new replies.