Support

Account

Home Forums Front-end Issues do_shortcode filled with variable

Solving

do_shortcode filled with variable

  • Hello everybody,
    This should be an easy one, but in turns me mad.
    Lets write this code :

    $formPerso = '[contact-form-7 id="181" title="Form1"]';
    do_shortcode($formPerso);

    This provides me a form made with CF7. And it works.

    Now I’d like to let my website author choose which form to use in a page, so I created an ACF text field and my author has to fill it with a CF7 shortcode (ex: [contact-form-7 id=”181″ title=”Form1″]).
    Now in my code I put this :

    $formPerso = get_field('form_perso');
    do_shortcode($formPerso);

    The front-end result is : [contact-form-7 404 “Not Found”]
    no form only this part of shortcode.
    Does somebody have an idea how to make it works?

  • what is the value of form_perso field?

    $formPerso = get_field('form_perso');
    echo '<pre>';
    echo htmlspecialchars(print_r($formPerso,true));
    echo '</pre>';

    why you didnt try out ACF CF7 Field Plugin?
    create a ACF CF7 Field with name selected_form and show it at frontend:

    <?php if( get_field('selected_form') ):
         the_field('selected_form');
    endif; ?>

    maybe this solve problem too:

    $formPerso = get_field('form_perso', false, false);
    do_shortcode($formPerso);
  • Hi, this post is very old but I just did this myself.

    Heres what you need:

    <?php $contactform = get_field(‘contact_form_shortcode’); ?>

    <div id=”contact-form”>
    <?php echo do_shortcode($contactform) ?>
    </div>

  • Yes, this is old one but had me stumped for a while.


    @gweb89
    your solution didn’t work for me as @trouille2 said it gives [contact-form-7 404 “Not Found”]


    @mediawerk
    solution worked for me …

    echo do_shortcode(get_field(‘form_shortcode’, false, false));

    Also the ACF CF7 Field Plugin mentioned is no longer supported.

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

The topic ‘do_shortcode filled with variable’ is closed to new replies.