Support

Account

Home Forums ACF PRO Can't Save Post if I Add a URL to a Text/URL Field???

Solved

Can't Save Post if I Add a URL to a Text/URL Field???

  • Hello, I think this is a bug, but it might just be me somehow. Anyways, after upgrading the ACF Pro from the previously free version of ACF, I had to update my frontend forms.

    The problem, however is that all of the articles had a custom field that had a URL in it. Normally, this wouldn’t be a problem because in ACF 4, posts would save just fine. However, I’ve noticed that in ACF 5, if there’s a URL in this field or if there previously was a URL in that field, it will not save and just redirect me back to a blank form.

    I tried using all of the text fields and I even used the WYSIWYG field, but none of them work. I didn’t have this problem in ACF 4, so I’m wondering what happened to frontend forms and URLs, and if possible, a fix for it ASAP.

    The screenshot attached is a screenshot of a new post I’m trying to make, and it won’t go unless I remove “http://” from the field. This screenshot (http://puu.sh/brt59/017e980a44.png) is a screenshot of a post I have already made and because it has a URL in the “Download Link” field, I can’t click “Submit” without it just redirecting me to a blank form.

    I feel like it’s a new security feature or something.

  • Update: Oh might I add, it DOES go through if I add the URL through the backend editor, however.

    Quick Update: It also doesn’t go through with the oEmbed field. It seems like it does this with all of the custom fields as long as there’s “http://” in the string. Is there any way around this?

    Another Update: Deactivated all plugins to see if it was a conflict, and still nothing.

    Again, this wasn’t a problem in ACF 4. I’m not really sure what to do at this point, and I don’t really want to downgrade to ACF 4 because I already paid for ACF 5 :/

  • Hi @BlueOrchard

    Thanks for the bug report. Is it possible that you have some theme code which is interacting with the acf_form data on save?

    Also, can you please enable DEBUG_MODE in your wp-config.php and watch for any PHP errors during the save of the form.

  • Hmm… I enabled WP debug and I saw this appear repeatedly throughout the site:

    Notice: is_main_query was called incorrectly. In pre_get_posts, use the WP_Query::is_main_query() method, not the is_main_query() function. See http://codex.wordpress.org/Function_Reference/is_main_query. Please see Debugging in WordPress for more information. (This message was added in version 3.7.) in /home/onestopmods/public_html/wp-includes/functions.php on line 3245
    

    I deactivated the plugin, but I couldn’t access the site after that because of a get_field error (I assume this is normal if the plugin is deactivated) so I can’t really say if the plugin is the one causing this.

    Also, if debug mode is on and if the plugin is enabled, I’m unable to even click “submit”.

    Here’s the code for my “Add Post” page:

    <?php 
    /*
    Template Name: Add Post
    */
    acf_form_head();
    get_header(); 
    $specat = $_GET['cat'];
    	if($specat == 2){$namecat = Minecraft;}
    ?>
    
    <div id="main" class="full-width"><div class="wrap cf">
    
    	<div id="content" role="main">
    	
    		<?php while (have_posts()) : the_post(); ?>
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h1 class="page-title">Submitting a Mod for: <?php echo $namecat; ?></h1>
    
    			<div class="page-content rich-content">
    			<?php 
    			if($specat == 2){$specicat = 1193;}
    			acf_form(array(
    					'post_title' => true,
    					'post_content' => true,
    					'post_id'		=> 'new_post',
    					'new_post'		=> array(
    						'post_title'  => 'New Post',
    						'post_type'		=> 'post',
    						'post_status'		=> 'pending',
    						'post_category'  => array("$specat") ,
    					),
    					'field_groups' => array( 1185, 1191, $specicat, 1197, 1200),
    					'submit_value'	=> 'Submit Your Mod',
    					'return' => 'http://onestopmods.com/view-mods/',
    				)); ?>
    			</div>
    		</div><!--end .hentry-->
    		<?php endwhile; ?>
    		
    	</div><!--end #content-->
    
    </div></div><!-- end #main -->
    
    <?php get_footer(); ?>
  • Quick Update: I fixed the main_query problem (it was my theme), but the problem still persists. I can’t click the “submit” button when I’m debug mode.

  • So I tried submitting, waiting until it finished submitting, and then turned debug mode on. Here’s some of the errors I got:

    Notice: Undefined offset: 0 in /home/onestopmods/public_html/wp-content/themes/osmMK2/template-editpost.php on line 22
    
    Notice: Trying to get property of non-object in /home/onestopmods/public_html/wp-content/themes/osmMK2/template-editpost.php on line 22
    
    Notice: Undefined variable: specicat in /home/onestopmods/public_html/wp-content/themes/osmMK2/template-editpost.php on line 31

    and here’s the contents of my “editpost.php”:

    <?php 
    /*
    Template Name: Edit Post
    */
    acf_form_head();
    get_header();
    $postide = $_GET['id'];
    ?>
    
    <div id="main" class="full-width"><div class="wrap cf">
    
    	<div id="content" role="main">
    	
    		<?php while (have_posts()) : the_post(); ?>
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h1 class="page-title">Editing Mod: <?php echo get_the_title("$postide"); ?></h1>
    
    			<div class="page-content rich-content">
    			<?php if ( current_user_can('edit_post', $postide) ) { ?>
    			<?php
    				$category = get_the_category("$postide"); 
    					$specat = $category[0]->cat_ID;
    						if($specat == 2){$namecat = Minecraft;}
    			?>
    			<?php 
    				if($specat == 2){$specicat = 1193;}
    			acf_form(array(
    				'post_id' => "$postide",
    				'post_title' => true,
    				'post_content' => true,
    				'field_groups' => array( 1185, 1191, $specicat, 1197, 1200),
    				'submit_value'	=> 'Submit Changes',
    				'return' => 'http://onestopmods.com/view-mods/',
    			)); 
    			?>
    			<?php } else { echo 'You do not have permission to access this page. If you are not logged in, try logging in. If you believe that this is an error, please <a href="http://onestopmods.com/contact/">Contact Us.</a>';} ?>
    			</div>
    		</div><!--end .hentry-->
    		<?php endwhile; ?>
    		
    	</div><!--end #content-->
    
    </div></div><!-- end #main -->
    
    <?php get_footer(); ?>

    It says the variables are undefined, but I’m getting them through a query string in the URL. Is this not possible to fix?

    I’d also like to note that these errors don’t show up when I initially load up the edit form. It only happens when I click submit and it redirects me to the same url, but with blank values everywhere. This error also doesn’t happen if there aren’t URLs (http://) in the fields.

  • Hello,

    When I add a url to an option page text box or url field and press save. I too get a blank page / 404 page.

  • Glad to see I’m not the only one with this problem. I mean, it sure is inconvenient, but I was getting worried that it was on my end and I couldn’t find out why.

    Hopefully this will get fixed soon as my website really requires this function in order to fully function properly.

  • Hi @BlueOrchard

    Thanks for the code.

    The errors suggest that variable do not exist. Looking at your code, there are definitely situations where the variable $specat does not exist.

    For example, what if the $specat value is ‘1’ instead of ‘2’?

    
    if($specat == 2){$specicat = 1193;}
    

    Please fix all PHP errors within your theme, and the ACF form should redirect as it should.

    @Made Responsively Can you please turn on DEBUG_MODE too? Do you get any PHP errors which saving the options page?

  • Had a similar problem as this, and the solution ended up being to modify two rules in our ModSecurity settings.

    We’re with liquidweb, and they are the ones who figured this out.

    I don’t know ModSecurity at all, so I don’t know if the rule ID’s are a standardized thing, or if they are unique to each server setup, but for us, the two rules were:

    340464, and 340465

    The “Justification” for both of these rules were identical:
    Match of "rx ://%{SERVER_NAME}/" against "ARGS:acf[field_52881450ecaab]" required.

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

The topic ‘Can't Save Post if I Add a URL to a Text/URL Field???’ is closed to new replies.