Support

Account

Forum Replies Created

  • Resolved. I can’t believe this, but my host has some really aggressive object caching. I disabled and flushed the cache hours ago and that didn’t help but apparently there was some things going on in the back.

  • Thanks @elliot

    I had done another extensive project with ACF5 and I think was making a few assumptions on handling of post update/insert.

    Aside from reverting back to ‘post_id’ => ‘new’ on the acf_form call and the pre_save_post, I changed the $_POST[‘return’] to $GLOBALS[‘acf_form’][‘return’] and it looks like we’re back to normal.

    As always, thanks for your time and an excellent plugin.

  • Hi @elliot

    Okay, I’ve worked on this a bit.

    I think the confusion before was the fact I was trying to migrate from V4 to V5. It seems I’ve discovered the following, and please correct me if I am wrong:

    – I see the V5 no longer needs acf/pre_save_post filter to insert a post. However, I was relying on this to add_query_arg a few variables. Specifically, the newly created post ID and the listing type which was being pulled with:
    $listing_type = $_POST['bh_post_type']

    If it’s a successful post, I want to simply add 4 query arguments, 2 of those being what I stated above. In V4, i used that filter to handle the post insert and return URL just as you had laid out for me earlier in this thread.

  • Yea, I was updating from v4 to v5.

    The second post of code, as you obviously know, was used to actually use the form data to create a post.

    $_POST['bh_post_type'];

    Was used for v4 obviously. I tried appending $GLOBALS[‘acf_form’] to that in place of $_POST and it did not work. So I tried reverting it back to $_POST to see if an object being sent over instead of single variables.

    I noticed the new vs new_post shortly after posting and still didn’t work.

    I’ll keep debugging and report back when I’m able. Thanks.

  • Hi @elliot

    EDIT: Okay, I was able to fix it not going to /publish/ but now it’s not adding the query args still. Thanks.

    Thanks for responding to this after almost 2 years. I was in the middle of creating a new service when ACF 5 came out, so I didn’t have issues with implementing it. However, I’m now updating my other site for ACF5 and I’ve ran into this issue with the redirect.

    I’ve tried a few things and I can’t seem to get it to redirect to a) the declared page (in my case, a /publish/ page… I am saving submission as draft and the publish page is for a payment gateway.) and b) with the query args needed to supply the logic to the publish page.

    Any thoughts on this? I’m happy to share my source code. Your plugin has made two pretty large sites successful.

    $args = array(
    							'post_id' => 'new_post',
    							'new_post' => array(
    						        'post_status' => 'draft',
    						        'post_type'  => $cpt,
    						        //'post_title' => 'new listing'
    							),
    							'html_before_fields' => $htmlbefore,
    							'field_groups' => $fieldgroups,
    							'form_attributes' => array('class' => $formattr,'autocomplete' => 'false'),
    							'return' => home_url('publish/'),
    							'submit_value' => 'Submit Listing'
    						);
    
    						acf_form( $args );

    That’s the form.

    And here is one of the pre_save_post functions:

    function my_pre_save_post( $post_id )
    	{
    	    // check if this is to be a new post
    	    if( $post_id != 'new' ) {
    	        return $post_id;
    	    }
    
    	    // Get Post Type
    	    $listing_type = $_POST['acf_form']['bh_post_type'];
    	    $perftype = $_POST['acf_form']['bh_perf_org_type'];
    	 
    	   // Create a new post
    	    $post = array(
    	        'post_status' => 'draft',
    	        'post_type'  => $listing_type,
    	        'post_title' => 'new listing'
    	    );  
    	 
    	   // insert the post
    	    $post_id = wp_insert_post( $post );
    
    	    if ($perftype) {
    	    	update_post_meta( $post_id, 'bh_perf_org_type', $perftype );
    	    }
    
            $query_args = array(
                'pid' => $post_id,
                'step' => 'pick',
                'ptype' => $listing_type,
                'msg' => 'success'
            );
    
            
    
    	    // update $_POST['return']
        	 $_POST['acf_form']['return'] = add_query_arg( $query_args,  $_POST['acf_form']['return'] );
    	 
    	    // return the new ID
    	    return $post_id;
    	}
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );

    I know you said $GLOBALS above there and I tried that, but no go, so I went back to $_POST. I didn’t run into this with my other site but it’s also set to return to the same page with just some queries (post is added through a modal).

    Thanks in advance if you notice anything!

    Chris

  • Was wondering if there was any insight on this? I need to proceed with the project and will have to make several adaptations for it to work properly.

    Thanks

  • I had a work around for this, then somehow something was changed with ACF and I had to desperately remove my function (similar to yours posted above) so people could keep uploading images. Once I figure my solution out again, I’ll try to remember to post it here.

    This is a big deal that needs to be worked around hopefully in v5, if not, shortly after.

  • Is this something new? Because I had this restricted successfully before. I am sitting on the couch without my work computer so I can’t check. Unless something was changed in recent versions of ACF, my solution was working fine. It has nothing to do with ACF, though that would be an excellent addition as no one would want others to have access to others images.

  • Are you reloading the post_id maybe? Or possibly your browser is saving the form fields values.

  • Hi.

    You will need to check the values of each date and compare it with the current date.

    First, declare a variable with the current unix time before you run through all the date checks.

    $now = time();

    This will save the unix time stamp which is a long number that makes no sense until converted into a human readable format. Basically, its the number of seconds from the UNIX epoch, or January 1st, 1970.

    This value will automatically update everytime the function is called of course.

    Now, between each check if a value exists for a key, don’t immediately print the field value with the_field(‘key’) function. Instead, compare it now to the $now variable you just declared. Compare it like this:

    
    $date_one_timestamp = strtotime(get_field('date_one));
    if ($now < $date_one_timestamp ) {
    // Since the the date is ahead of the absolute second of now
    // we will echo the timestamp using the date function, and format it like
    // "January 20, 2014"
    
    echo date("F j, Y", $date_one_timestamp);
    
    } else {
    // do nothing or do something else
    // because the unix time stamp of the date is greater then this second in time
    }
    

    Now, this assumes that for the date field in ACF, you saved it using a format that can be read by the php strtotime function. More on that can be read here:
    http://us3.php.net/manual/en/function.strtotime.php

    But as you will read, the best way to format it is YYYY-MM-DD
    Since that will keep from ambiguity when its trying to figure out what each numbers mean.

    Hope that helps.

    Last bit, for more efficient code and presentation for yourself/clients when delcaring these dates, consider purchasing the Repeater Field addon. Then again, @elliot is about to turn all addons into a complete ACF Pro plugin, so maybe hold off too. Repeater addon is great, as is the rest of the addons.

    Btw, I don’t work for Elliot, just helping out. This is seriously the best plugin available for WP and powers 2 of my projects that I have highly customized.

  • Hi @elliot,

    I went ahead and copy/pasted the latest datepicker build from jQuery UI and it works now. Your specific input JS seems to be fine.

  • Just noticed this same issue today. All attachments are getting the ID of the page that the form resides on.

    I am assuming this was the same issue, and am looking forward to the fix. Makes for some trouble with permissions/capabilities.

  • Hi @elliot,

    Okay, thanks for the clarification. I figured something wasn’t filtering in. That’s great news on making more options for ACF front end. For now, I am making some cool adjustments via the message field and simply adding wrapping divs for some neat combining with Bootstrap.

    Anyhow, RE the validation.. Yes, ACF is validating correctly, I think I phrased this question incorrectly. I would like to change the text for the validation error so its a little more user friendly… So something like “Opps, looks like something is missing” as opposed to the word “invalid.”

    Along those lines also, is there a way to place the validation error message next to the submit button? This again is regarding the front end submission.

    A couple suggestions that would be awesome regarding validation are:

    – the above if not currently possible
    – With the “Tabs” auto grouping, that the tab gets a class “acf-group-contains-error” or something if a field within the tab group has a validation error. This would allow styling of that tab to make it more obvious to the user.
    – Individual validation messages per field. So if I have a phone number field, i could customize the message for that specfic field to be “Please provide your phone number.” as opposed to a generic “field is required.”

    I tried messing around with some jQ to get the above working but was unsuccessful. I am definitely not the type to request something without first trying at least.

    Made the simple changes of .live to .on in all the addons, so I’m not worried.

    Thanks Elliot.

  • Hi @elliot,

    When I submit a form on front end and the validation turns up error, the message is: Validation Failed. One or more fields below are required.

    How would you suggest I alter that?

  • Thanks @elliot,

    Yes, definitely coming from line 205 in the repeater addon, input.js file, says Mr. Firebug.

    Any idea on how I can customize the validation error message, aside from tampering with the plugin files?

  • hi @Jonathan,

    Yes, it’s a development site so I’m not worried, just making sure @elliot was aware which I am sure he is.

    “rofl” is a good quick search in source, unless of course that is commonly used in your framework 😉

    Thanks.

    Slightly off-topic, but as I’m continuing to work, what about a ‘html_validation_error_msg’ field as well? Or is there a filter I can use for that? I’d like to make the validation error message a little more friendly since it’s a front-end form.

  • @elliot,

    Thank you so very much! Works perfectly.

  • Hi @elliot,

    Yes, I’ve followed the docs to create the front end form and it works fine. I see that the function creates a new post when the post_id == ‘new’, and the WP core does that automatically if I remember, if a post ID isn’t supplied when creating a post.

    However, I’m unsure how to retrieve the post ID once ACF has created it. I know how to insert it after for the redirect URL, just not sure how to throw it into a variable to begin with.

    Thanks.

  • Hi @elliot,

    Yes, that was it. I never realized there was a max character for CF keys!

    Fortunately, that’s the only one that extends that long, so I’ll start to use abbreviations when possible. do_cf_res_item_con works I suppose.

    Thanks again. Excellent plugin. I’ve purchased 3 of your add ons and use ACF on several projects.

  • Wait. I’m sorry, I was wrong and for the double post.

    The database is not saving the value. So its nothing at all with my front end code at this point.

    Something isn’t saving correctly to the database. When I enter lorem, I save options, leave page, go back to page, the WYSIWYG editor is blank again.

  • I get:

    
    Array
    (
        [0] => Array
            (
                [do_cf_resume_item_block_title] => programs
                [do_cf_resume_item_block_content] => 
            )
    
        [1] => Array
            (
                [do_cf_resume_item_block_title] => training
                [do_cf_resume_item_block_content] => 
            )
    
        [2] => Array
            (
                [do_cf_resume_item_block_title] => OtherTITLE
                [do_cf_resume_item_block_content] => 
            )
    
    )
    

    There is definitely something being written to the database though. When i leave the page and revisit (the options page in backend), it will have the value there waiting for me.

  • Oh, I see, you meant the $contentgo if statement.

    Yea, i was doing that for testing and had the contentgo var being loaded with something else… i’ve spruced everything up and its still unfortunately not working.

    Code as of now:

    
    
    	if ( get_field('do_cf_resume_item_block','option') ) :
    		
    		echo '<div class="resume-block-container">';
    
    			while ( has_sub_field('do_cf_resume_item_block','option') ) : 
    
    				// Get Vars
    
    				$content = get_sub_field('do_cf_resume_item_block_content');
    				$gettitle = get_sub_field('do_cf_resume_item_block_title');
    				$title = do_resume_block_title_display($gettitle);
    				
    
    				echo '<div class="resume-block-item">';
    
    					echo '<h3>' . $title . '</h3>';
    
    					echo '<div class="resume-block-item-content">' . $content . '</div>';
    
    					if (empty($content)) echo 'Nothing here.';
    
    				echo '</div>';
    
    			endwhile;	
    
    		echo '</div>';
    
    	endif;
    
  • Hi @Elliot,

    Okay, that makes sense about the 2nd parameter and I’m sure that will fix it.

    But the If statement… I actually got that code here without thinking about it much:

    <?php if(get_field('repeater_field_name')): ?>

    From: http://www.advancedcustomfields.com/resources/field-types/repeater/

  • 
    	if ( get_field('do_cf_resume_item_block','option') ) :
    
    		echo '<div class="resume-block-container">';
    
    			while ( has_sub_field('do_cf_resume_item_block','option') ) : 
    
    				// Get Vars
    
    				$content = get_sub_field('do_cf_resume_item_block_content','option');
    				$gettitle = get_sub_field('do_cf_resume_item_block_title','option');
    				$title = do_resume_block_title_display($gettitle);
    				
    
    				echo '<div class="resume-block-item">';
    
    					echo '<h3>' . $title . '</h3>';
    
    					echo '<div class="resume-block-item-content">' . $content . '</div>';
    
    					if (empty($contentgo)) echo 'Nothing here.';
    
    				echo '</div>';
    
    			endwhile;	
    
    		echo '</div>';
    
    	endif;
    

    Thanks.

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