Support

Account

Home Forums Front-end Issues Add new post with ACF in front-end form

Unread

Add new post with ACF in front-end form

  • I have a custom form on my front end where ppl can add items (post_type = item)
    I would like to show the ACF form in here as wel; What i did was getting the acf using:
    get_field_object()

    with this object i rebuild the form as it was shown wele editing a post (post.php)

    <div class="input-group">
    					 			<div id="acf-vanaf" class="field field_type-date_time_picker field_key-<?=$field['key']?> required" data-field_name="vanaf" data-field_key="<?=$field['key']?>" data-field_type="date_time_picker">
    								  <span class="input-group-addon"><?=$field['label']?></span>
    									<input type="text" value="<?=$field['value']?>" name="fields[<?=$field['key']?>]" class="ps_timepicker active hasDatepicker" data-picker="slider" data-date_format="dd-mm-yy" data-time_format="HH:mm" data-show_week_number="false" title="Vanaf" placeholder="dd-mm-yy HH:mm" id="dp1413034012076" data-cip-id="dp1413034012076">
    								</div> 
    							</div>


    Now, this works only if i am editing a existing item(post). When i try to ad a new post the ACF fields are ignored.

    Note i use a AJAX fucntion to save my form to admin-ajax.php

    $("body").on("click", ".item_submit", function(){
    				var options = {};
    				options.type = "post";
    				options.url = "<?php echo admin_url('admin-ajax.php');?>";
    				options.data = $("#frm_item").serialize();
    				options.dataType = "json";
    				options.error = function(e){ alert("<?php _e('Server Error : ','javo_fr');?>" + e.state() ); console.log( e.responseText ); };
    				options.success = function(d){
    					if(d.result == true){
    						var is_pending = $('[name="javo_add_item_disabled"]').val() == 'use'? true: false;
    						var cm_pending = $('[name="javo_add_item_disabled_comment"]').val();
    						var str;
    						window.transmission = true;
    						switch(d.status){
    							case "edit":
    								str = is_pending ? cm_pending : "<?php echo $alerts['item_edit_success'];?>";
    								$.javo_msg({ content: str, delay:5000 }, function(){
    									location.href = d.link;
    								});
    							break;
    							case "new": default:
    								if( is_pending ){
    									$.javo_msg({ content: cm_pending, delay:5000 }, function(){
    										location.href = d.link;
    									});
    									return false;
    								}
    								if( d.paid ){
    									$("input[name='post_id']").val( d.post_id );
    									$("form#javo_add_item_step1").submit();
    								}else{
    									$.javo_msg({ content: "<?php echo $alerts['item_new_success'];?>", delay:5000 }, function(){
    										location.href = d.link;
    									});
    								};
    
    						}
    					}
    				};
    
    				if( chk_null( 'txt_title', "<?php echo $alerts['title_null'];?>") == false ) return false;
    				if( chk_null( 'txt_content', "<?php echo $alerts['content_null'];?>", "textarea") == false ) return false;
    
    				if( $("#javo-item-gpsLatitude, #javo-item-gpsLongitude").val() == ""){
    					$("#javo-item-address").addClass("isNull").focus();
    					alert("<?php echo $alerts['latlng_null'];?>");
    					return false;
    				};
    				$.ajax(options);
    			});

    i’ve tried adding acf_form_head(); and acf_form()

    PS. i have noticed that i first need to set a value in my ACF in post.php before i can eddit/ alter the value from my custom form in the frond-end. i think this is important information

Viewing 1 post (of 1 total)

The topic ‘Add new post with ACF in front-end form’ is closed to new replies.