Support

Account

Forum Replies Created

  • Hi

    in above solution we are not using acf form we are going to use htmlform mean create form in a wp page template with your required fileds for example if u create three fields in acf like Author Image Title Image then create similar form in html and

    <form method=”post” action=”#” class=”acf-form form-horizontal ” id=”post” enctype=”multipart/form-data”>
    <?php
    $args = array(
    ‘post_id’ => ‘new’,
    ‘field_groups’ => array(1), //use wrong ID of your custom field Form soform fields will not get shown`
    ‘form’ => false

    );
    acf_form($args);
    ?>
    //file upload button

    <div data-field_type=”file” data-field_key=”field_5343d9b2586f0file” data-field_name=”email” class=”field field_type-text field_key-field_5343d9b2586f0file” id=”acf-file”>
    <p class=”label”><label for=”acf-field-file”>Image</label></p>
    <div class=”acf-input-wrap”>
    <input type=”file” id=”my_image_upload” name=”my_image_upload”>
    </div>
    <input id=”submit_my_image_upload” name=”submit_my_image_upload” type=”submit” value=”Submit” />

    The above form will be on u r wordpress page
    Now copy the following function to your themes function.php

    //img upload//

    function kv_handle_attachment($file_handler,$post_id,$set_thu=false) {
    <code>// check to make sure its a successful upload</code>
    if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();

    require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);

    require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’);

    $attach_id = media_handle_upload( $file_handler, $post_id );

    // If you want to set a featured image from your uploads.

    if ($set_thu) set_post_thumbnail($post_id, $attach_id);
    return $attach_id;
    }
    //New File Upload
    
    

    add_filter(‘acf/pre_save_post’ , ‘my_pre_save_post’ );
    function my_pre_save_post( $post_id ) {
    // check if this is to be a new post`

    if( $post_id != ‘new’ ) {
    return $post_id;
    }
    $field = $_POST['fields'];
    $post_title = $_POST['fullname'];
    $post_content = $field['edit_test2'];

    // Create a new post

    require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’);
    $attachment_id = media_handle_upload( ‘my_image_upload’, $post_id );
    $post = array(
    ‘post_status’ => ‘draft’ ,
    ‘post_title’ => $post_title,
    ‘post_content’ => $post_content,
    ‘post_type’ => ‘page’
    );
    $newpost_id=wp_insert_post($post);
    if($newpost_id!=0)
    {
    add_post_meta($newpost_id, ‘picture’, $attachment_id );

    // here u can add more fields which are present on u r form
    }
    }`

  • Hi

    after u create front end form pls put following function in your function.php, add the required filed to post

    add_filter(‘acf/pre_save_post’ , ‘my_pre_save_post’ );
    function my_pre_save_post( $post_id ) {
    // check if this is to be a new post
    if( $post_id != ‘new’ ) {
    return $post_id;
    }

    $field = $_POST[‘fields’];
    $post_title = $_POST[‘fullname’];
    $post_content = $field[‘edit_test2’];
    $post = array(
    ‘post_status’ => ‘draft’ ,
    ‘post_title’ => $post_title,
    ‘post_content’ => $post_content,
    ‘post_type’ => ‘page’

    );
    $newpost_id=wp_insert_post($post);
    if($newpost_id!=0)
    {

    $fullname=$_POST[‘fullname’];
    $address=$_POST[‘address’];
    add_post_meta($newpost_id,’FullName’, $fullname);
    add_post_meta($newpost_id, ‘address’, $address);
    }
    }

    You can also refer following article
    http://www.advancedcustomfields.com/resources/tutorials/using-acf_form-to-create-a-new-post/

  • Hi here is solutions create html form

    <form method=”post” action=”#” class=”acf-form form-horizontal ” id=”post” enctype=”multipart/form-data”>
    <?php
    $args = array(
    ‘post_id’ => ‘new’,
    ‘field_groups’ => array(1), //use wrong ID of your custom field Form so form fields will not get shown
    ‘form’ => false
    );
    acf_form($args);
    ?>
    //file upload button
    <div data-field_type=”file” data-field_key=”field_5343d9b2586f0file” data-field_name=”email” class=”field field_type-text field_key-field_5343d9b2586f0file” id=”acf-file”>
    <p class=”label”><label for=”acf-field-file”>Image</label></p>
    <div class=”acf-input-wrap”>
    <input type=”file” id=”my_image_upload” name=”my_image_upload”>
    </div>
    <input id=”submit_my_image_upload” name=”submit_my_image_upload” type=”submit” value=”Submit” />

    // in function .php write following code
    //Here we gather the files which sent by the HTML forms. and send it to //another function called kv_handle_attachement(). This is a simple function //this will help you to store the files to your wp uploads directory. Add //the following code into your Theme “ functions.php”
    //img upload//
    function kv_handle_attachment($file_handler,$post_id,$set_thu=false) {
    // check to make sure its a successful upload
    if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false();

    require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’);

    $attach_id = media_handle_upload( $file_handler, $post_id );

    // If you want to set a featured image from your uploads.
    if ($set_thu) set_post_thumbnail($post_id, $attach_id);
    return $attach_id;
    }
    //New File Upload

    add_filter(‘acf/pre_save_post’ , ‘my_pre_save_post’ );
    function my_pre_save_post( $post_id ) {
    // check if this is to be a new post
    if( $post_id != ‘new’ ) {
    return $post_id;
    }

    $field = $_POST[‘fields’];
    $post_title = $_POST[‘fullname’];
    $post_content = $field[‘edit_test2’];

    // Create a new post
    require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’);
    $attachment_id = media_handle_upload( ‘my_image_upload’, $post_id );
    $post = array(
    ‘post_status’ => ‘draft’ ,
    ‘post_title’ => $post_title,
    ‘post_content’ => $post_content,
    ‘post_type’ => ‘page’

    );
    $newpost_id=wp_insert_post($post);
    if($newpost_id!=0)
    {

    add_post_meta($newpost_id, ‘picture’, $attachment_id );

    }
    }`

    Let me know if u have any question , its works perfectly fine

    Thanks

  • hi

    it seems the problem is related wp permission can u try by creating a new admin user and and then try to submit the contents
    Also did you added any new function in function.php to save contents in draft mode,or are u using seprate wp template to save/edit custom post type

  • hi

    have you tried some code pls share I will suggest you change it seems all of your requirements are related PHP coding

    If your requirements are limited to following only

    How not to show the library files when uploading the front end?
    1) create html form to upload image
    http://www.kvcodes.com/2013/12/create-front-end-multiple-file-upload-wordpress/

    2) How to define the format of files that can attached?
    Refer following code here u can limit type file to be uploaded
    3) How to limit the amount of files that can be attached?
    by following code u can limit the size of file

    <?php
    $allowedExts = array(“gif”, “jpeg”, “jpg”, “png”);
    $temp = explode(“.”, $_FILES[“file”][“name”]);
    $extension = end($temp);

    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    || ($_FILES["file"]["type"] == "image/x-png")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 20000)
    && in_array($extension, $allowedExts)) {
    if ($_FILES["file"]["error"] > 0) {
    echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
    } else {
    echo "Invalid file";
    }
    ?>

  • hi

    many user facing this problem and no proper solution for this, but here is work around for this issue , We will not use acf_form rather than that we need to create a html form

    create html form

    `<form method=”post” action=”#” class=”acf-form form-horizontal ” id=”post” enctype=”multipart/form-data”>
    <?php
    $args = array(
    ‘post_id’ => ‘new’,
    ‘field_groups’ => array(1), //use wrong ID of your custom field Form so form fields will not get shown
    ‘form’ => false
    );
    acf_form($args);
    ?>
    //file upload button
    <div data-field_type=”file” data-field_key=”field_5343d9b2586f0file” data-field_name=”email” class=”field field_type-text field_key-field_5343d9b2586f0file” id=”acf-file”>
    <p class=”label”><label for=”acf-field-file”>Image</label></p>
    <div class=”acf-input-wrap”>
    <input type=”file” id=”my_image_upload” name=”my_image_upload”>
    </div>
    <input id=”submit_my_image_upload” name=”submit_my_image_upload” type=”submit” value=”Submit” />

    // in function .php write following code
    //Here we gather the files which sent by the HTML forms. and send it to //another function called kv_handle_attachement(). This is a simple function //this will help you to store the files to your wp uploads directory. Add //the following code into your Theme “ functions.php”
    //img upload//
    function kv_handle_attachment($file_handler,$post_id,$set_thu=false) {
    // check to make sure its a successful upload
    if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false();

    require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’);

    $attach_id = media_handle_upload( $file_handler, $post_id );

    // If you want to set a featured image from your uploads.
    if ($set_thu) set_post_thumbnail($post_id, $attach_id);
    return $attach_id;
    }
    //New File Upload

    add_filter(‘acf/pre_save_post’ , ‘my_pre_save_post’ );
    function my_pre_save_post( $post_id ) {
    // check if this is to be a new post
    if( $post_id != ‘new’ ) {
    return $post_id;
    }

    $field = $_POST[‘fields’];
    $post_title = $_POST[‘fullname’];
    $post_content = $field[‘edit_test2’];

    // Create a new post
    require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’);
    require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’);
    $attachment_id = media_handle_upload( ‘my_image_upload’, $post_id );
    $post = array(
    ‘post_status’ => ‘draft’ ,
    ‘post_title’ => $post_title,
    ‘post_content’ => $post_content,
    ‘post_type’ => ‘page’

    );
    $newpost_id=wp_insert_post($post);
    if($newpost_id!=0)
    {

    add_post_meta($newpost_id, ‘picture’, $attachment_id );

    }
    }`

    Let me know if u have any question , its works perfectly fine

    Thanks

  • hi

    Any one pls help

    Thanks

  • Hi

    I even tried by using the exact code which is shown in following article
    http://www.advancedcustomfields.com/resources/how-to/create-a-front-end-form/

    but still Add Image button gives same error

    I did one small test I tried by removing header, and I found that now I can see two options near Add Image button – (Remove,Edit) these buttons are not getting shown when we use header so some thing issue with js files if u required I can give wp login details and cpanel access

    http://ezwebstore.in/health/add-new-service/

    Thanks

  • Hi

    Following is the template code
    <?php

    /* Template Name: Add Service

    */
    acf_form_head();
    the_post();
    ?>
    <?php include (TEMPLATEPATH . ‘/header-inner.php’); ?>
    <section id=”main_content”>
    <div class=”container”>
    <div class=”row”>
    <div class=”col-lg-10 col-md-15 col-sm-15″>
    <div class=”col-item”>
    <span class=”ribbon_course”></span>
    <div class=”photo”>
    <div class=”cat_row voilet”>Input Here</div>
    </div>
    <div class=”info voilet-text”>
    <div class=”row add_bottom_5″>
    <div class=”form-body”>
    <div class=”col-md-8″>
    <div id=”primary”>
    <div id=”content” role=”main”>
    <?php
    $args = array(
    ‘post_id’ => ‘new’,
    ‘field_groups’ => array( 5303 )
    );
    acf_form( $args );
    ?>
    </div><!– #content –>
    </div><!– #primary –>
    </div>
    </div>
    </div>
    </div>
    </div><!– End row –>
    </div><!– End container –>
    </section><!– End main_content –>
    <?php get_footer(); ?>

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