Choose File in custom table

Support MB Custom Table Choose File in custom tableResolved

Viewing 15 posts - 1 through 15 (of 24 total)
  • Author
    Posts
  • #14737
    tsttechtsttech
    Participant

    Dear Anh,

    How would I store a "Choose File" in a custom table?

    Thank you
    Dave

    #14738
    tsttechtsttech
    Participant

    Or how to store the file path in the custom table?

    #14742
    Anh TranAnh Tran
    Keymaster

    Hi Dave,

    All media fields store attachment IDs by default. If you want to store file URL (not path), then you can try file field with upload_dir settings. See this for details:

    https://docs.metabox.io/fields/file/#upload-to-custom-folder

    #14747
    tsttechtsttech
    Participant

    Dear Anh,
    Which is correct way storing the ID or the path? I just want to store the information in the custom table which is why i am asking. As I don't know.

    Thank you
    Dave

    #14749
    Anh TranAnh Tran
    Keymaster

    Hi Dave,

    Storing ID seems better in my opinion. You can get full file info later with small piece of code. Storing file path doesn't have any benefit since it's the raw path on the server, which is unusable.

    #14752
    tsttechtsttech
    Participant

    Dear Anh,

    Ok, this does help, but now the problem is how does one store the ID.

    This is what i have already and all is working except the 'image_26' => 'VARCHAR(20)',

    add_action( 'init', 'prefix_create_table' );
    function prefix_create_table() {
        if ( ! class_exists( 'MB_Custom_Table_API' ) ) {
            return;
        }
        MB_Custom_Table_API::create( 'users_member_application_section', array(
            'application_date' => 'DATE NOT NULL',
            'company' => 'TEXT',
            'company_url' => 'TEXT',
            'company_details' => 'TEXT',
            'what_is_your_preferred' => 'TEXT',
            'other' => 'TEXT',
            'membership_level_youre_applying_for' => 'TEXT',
            'have_you_photographed_animalspets_before' => 'TEXT',
            'do_you_currently_offer_pro_bono' => 'TEXT',
            'if_yes_please_describe_the_services' => 'MEDIUMTEXT',
            'if_no_tell_us_a_little_more_about_why' => 'MEDIUMTEXT',
            'what_are_your_goals_of_membership' => 'MEDIUMTEXT',
            'primary_artistic_medium' => 'TEXT',
            'if_other_please_describe' => 'MEDIUMTEXT',
            'how_did_you_hear_about_hearts_speak' => 'TEXT',
            'if_someone_referred_you' => 'TEXT',
            'hearts_speak_members_provide_their_services' => 'TEXT',
            'if_so_please_provide_a_link' => 'VARCHAR(2083)',
            'i_have_read_and_agree_to_this_statement' => 'TEXT',
            'i_have_read_and_agree_to_adhere' => 'TEXT',
            'expired_members' => 'TEXT',
            'url_22_facebook' => 'VARCHAR(2083)',
            'url_23_instagram' => 'VARCHAR(2083)',
            'url_24_twitter' => 'VARCHAR(2083)',
            'url_25_google' => 'VARCHAR(2083)',
            'image_26' => 'VARCHAR(20)', 
            'text_27_ip_address' => 'VARCHAR(50) NOT NULL',
            'text_28_personal_facebook_account' => 'VARCHAR(2083)',
        ), array( 'text_27_ip_address' ) );
    }
    #14753
    tsttechtsttech
    Participant

    Also my array for the image is as follows.

    array (
    'id' => 'image_26',
    'type' => 'image',
    'name' => 'Business Logo',
    'max_file_uploads' => 2,

    #14754
    Anh TranAnh Tran
    Keymaster

    Probably you need to increase the length for the field. The value of image field is an array of IDs, which will be serialized before saving in the database.

    For example, if you have 2 images [12, 34], then the value will be a:2:{i:0;i:12;i:1;i:34;}. It's longer than what we think 🙂

    #14755
    tsttechtsttech
    Participant

    Dear Anh,
    I have increased the ‘image_26’ => ‘VARCHAR(2083)’, but its still not saving the image path or ID in the database.

    The database is just showing "NULL"

    Am i doing something incorrect?

    Dave.

    #14758
    Anh TranAnh Tran
    Keymaster

    I don't see anything wrong here. Do you see other fields saved in the database?

    #14760
    tsttechtsttech
    Participant

    Dear Anh,

    Yes other fields save, just the image one is not saving. The image field type is updating, but it doesn't store any data.

    I will choose a file and upload it then save the user profile, but the data is not getting updated in the custom table

    Dave.

    #14761
    Anh TranAnh Tran
    Keymaster

    If the field is updating, that means it still saves values in the post meta. Can you verify that?

    And did you put all the fields in one meta box?

    #14762
    tsttechtsttech
    Participant

    Dear Anh,

    I have checked the usermeta and its not saving the image_26 in there.

    Yes all the fields are in one meta box.

    https://pastebin.com/ZTiXff1h

    #14792
    tsttechtsttech
    Participant

    Dear Anh,

    Did you find anything wrong with my code that might cause this problem?

    Thank you
    Dave

    #14810
    tsttechtsttech
    Participant

    Dear Anh,

    Where you able to see if there was a problem with me code?

    Thank you
    Dave

Viewing 15 posts - 1 through 15 (of 24 total)
  • You must be logged in to reply to this topic.