• Resolved jordan141431

    (@jordan141431)


    I’m working on my client’s website. I’m wondering on How to pre-populate a form from a post ID. Thank you

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hi there @jordan141431

    I assume you’re referring to the Pre-populate option that appears under the Settings tab for each field, correct?

    Unfortunately, that cannot be used to pre-populate with data from a post. That is used to pre-populate a field with the value passed in a Redirect URL query parameter from another form.
    https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#pre-populate-form-field-values

    If you need to pre-populate fields with data from another source, like post data, you’d want to have a look through our Forminator API docs to see if there’s a method in there that could be useful for your needs:
    https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/

    However, for now, that would entail custom development that is beyond the scope of the support we can offer here I’m afraid.

    But this is an interesting question. Although I’m not sure how feasible it could be, I will bring it up with the developers to see if they have any ideas, or if it can be considered for a feature request.

    Cheers!
    Patrick

    Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hi again @jordan141431

    I just got a reply back from one of our developers, and it turns out this is simpler than I thought. ??

    The code below is an example of how to populate a text input field with the post title from a specified post ID.

    <?php
    add_filter( 'forminator_field_text_markup', function( $html, $field ) {
    	$post_id = 1;
    	$post    = get_post( $post_id );
    	if ( 'text-1' === $field['element_id']) {
    		$html = str_replace( 'value="post_populate"', 'value="' . $post->post_title . '"', $html );
    	}
    	return $html;
    }, 10, 2 );

    In this example, the post_id we’re fetching data from = 1, and the element_id of the form field we’re populating = text-1.

    The code will check if a default value of post_populate is set in any text-1 field, and replace it with the post_title of the specified post_id. If it doesn’t find that default value in any such text field, it won’t do anything.

    Please do let us know if this is what you’re looking for, or if you need further help with this.

    Cheers!
    Patrick

    Thread Starter jordan141431

    (@jordan141431)

    Hi Patrick,
    thank you for getting to my question. I was wondering how to pre-populate an input field from a specific post ID.

    thank you

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @jordan141431

    Could you extend it a bit more in the case of use?

    I can think in some cases, please let us know which is the task and we can find the best approach.

    The Post has a custom field and when you submit the form this field would be updated?

    Are you are using a Post form and would like to update the custom field?

    The Post has a custom field, the form will be embedded in this post and you would like to use that value in the form field?

    Best Regards
    Patrick Freitas

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @jordan141431

    I hope you are doing well and safe!

    We haven’t heard from you in a while, I’ll mark this thread as resolved.

    Feel free to let us know if you have any additional question or problem.

    Best Regards
    Patrick Freitas

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to pre-populate a form from a post ID’ is closed to new replies.