Custom Fields
Re-Envisioned
Support MB Frontend Submission How to set the post title to my Name input field?

This topic contains 11 replies, has 2 voices, and was last updated by  Anh Tran 1 year, 1 month ago.

  • Creator
    Topic
  • #9634

    LFFprop
    Participant

    Hi,

    Probably a very basic question, with a very simple answer…

    I am new to MB. Built my first meta boxes, and using the Frontend Submission extenstion to create a first post.
    One of the fields is a Name field. Another field is “Elevator pitch”
    How can I set the post title to this Name field?
    Similar: how can I set the post extract to the value of “Elevator pitch”?

    I see a lot of coding in the documentation. I was expecting with all these extensions that I woulld not have to deal with this coding myself.

    Thanks for your help.

Viewing 10 replies - 1 through 10 (of 11 total)
  • Author
    Replies
  • #9635

    Anh Tran
    Keymaster

    Hello,

    The post title is displayed in the post_fields attribute of the shortcode. Please use the MB Frontend Submission to add other fields to the form.

    In your situation, it sounds like changing the label for post title from “Post Title” to “Name”.

    So, please create a folder in your theme called mb-frontend-submission. Inside that folder, create a sub-folder called post. And inside post, create a file title.php, which contains the following code (don’t worry, just copy and paste):

    <?php
    $title = $data->post_id ? get_post_field( 'post_title', $data->post_id ) : '';
    $field = apply_filters( 'rwmb_frontend_post_title', array(
        'type' => 'text',
        'name' => esc_html__( 'Name', 'rwmb-frontend-submission' ),
        'id'   => 'post_title',
        'std'  => $title,
    ) );
    $field = RWMB_Field::call( 'normalize', $field );
    RWMB_Field::call( $field, 'admin_enqueue_scripts' );
    RWMB_Field::call( 'show', $field, false, $data->post_id );

    That’s it!

    Please try and let me know how it works.

    #9648

    LFFprop
    Participant

    Hi Anh,

    Thanks for your very quick respons. Impressed!

    Done as you requested, but no result.
    See here the title.php that I created like you said.
    https://1drv.ms/f/s!AiZg1q2e9vdxhBlxbs_Mz30DdS2c

    I have also tried with the same folder structure as for the template, like the Frontend Submission documentation describes.
    So I tried with as well as without the folder “template-parts” in the middle.
    No effect.

    #9649

    Anh Tran
    Keymaster

    I see you use the folder template-parts. It should be without it (probably you did it, but please try again), like in this screenshot:

    View post on imgur.com

    I’ve just tested and here is the result:

    View post on imgur.com

    #9666

    LFFprop
    Participant

    It’s not working unfortunately.
    I added quite a number of fields in the meta box. For some reason, it is even no longer creating a post when I press the submit button.

    Let me know if you need access to the site.

    #9671

    Anh Tran
    Keymaster

    Yes, please send me a temporary account to anhtnt@elightup.com. I’ll check it.

    #9674

    LFFprop
    Participant

    Done. I have created a page frontend-submission.
    Good luck.

    #9736

    Anh Tran
    Keymaster

    I’ve checked on your site and I see you created a field with ID post_title. But as it’s a field in a meta box, it can’t be a post field.

    To add post field, you need to change the shortcode to:

    [mb_frontend_form id="dominantgegevens,diensten" post_fields="title"]

    And the template for post title now works.

    Just a note: post fields (such as post title, editor, thumbnail, etc.) are not part of meta boxes, so you can’t wrap it in tabs. They will appear above the tabs.

    Here is the screenshot of the page:

    http://prntscr.com/jmu4hs

    #9768

    LFFprop
    Participant

    Thanks, that works great. I now see how to fill the standard WP post attribues, except the Category. I have tried to use the fiels Taxanomy, but that shows me a dropdown box, while I just want to hide it and assign a fixed value to it.
    Any suggestion?
    (I understand that this is different from my original question. If you want me to close this one and open a new thread, let me know.)

    #9776

    Anh Tran
    Keymaster

    Hi,

    To assign a fixed value to the category, use the taxonomy field. And set the default value (std parameter) to the category ID. Then that default value will be used when you submit the form.

    In order to hide the field, just add a custom CSS class to the field (like hidden) and add this line into your theme, or in Customizer > Additional CSS:

    .hidden { display: none; }

    That’s it. Please try and let me know how it goes.

    #9778

    LFFprop
    Participant

    The issue is that I don’t understand how to set the default value to the category in the meta box. I don’t see it in the options, and if I need to set it through custom attribute, then how?

Viewing 10 replies - 1 through 10 (of 11 total)

The topic ‘How to set the post title to my Name input field?’ is closed to new replies.