• Resolved Luis Correia

    (@simplewebpt)


    Hello,
    I would like my Course title field to have the name of the previous post where the registration button is and not the title of the form page.
    Thanks.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Luis Correia

    (@simplewebpt)

    Could you help me resolve this issue?

    Excuse my English, I’m Portuguese and I don’t speak it well.

    Hello, I can certainly help.

    On your course page, like this one, I would set the button’s destination URL with the post title as a parameter, like this:

    <a href="https://ceforcivil.magicbrain.pt/site/ficha-de-inscricao/?title=Seguran?a em Trabalhos em Altura e utiliza??o de arnês">INSCRI??O</a>

    To generate that button’s URL dynamically for all courses, that PHP would look something like this:

    <a href="https://ceforcivil.magicbrain.pt/site/ficha-de-inscricao/?title=<?php echo(esc_attr(urlencode(get_the_title()))); ?>">INSCRI??O</a>

    And then in the contact form, your form tag would look like this:

    [dynamic_text n-curso readonly "CF7_GET key='title']

    Let me know if that helps!

    Thread Starter Luis Correia

    (@simplewebpt)

    Good morning.
    Thanks for the answer.
    The first option worked perfectly.
    The second option “To generate that button’s URL dynamically for all courses, that PHP would look something like this:”, is not working.
    I put two links at the bottom of the page “https://ceforcivil.magicbrain.pt/site/seguranca-em-trabalhos-em-altura-e-utilizacao-de-arnes/&#8221;, one link with the first option, the other with the Second, if you could help me with the second option, I would be very grateful.

    Thread Starter Luis Correia

    (@simplewebpt)

    Ah, yes, I see the issue. The button is being inserted in a block so it converts the greater-than and less-than symbols into HTML entities so it doesn’t actually execute the code.

    One of the great things about our built-in shortcodes is that they can be used in content anywhere that shortcodes are evaluated! So what we’ll do is update your button to use our CF7_get_current_var shortcode to retrieve the title instead of the PHP. Okay, follow these steps, I’ll include pictures to help:

    With your paragraph highlighted in the editor, click the three-dots and choose “Edit as HTML.”

    Screenshot of the block editor in WordPress with the meatballs menu open on a paragraph block, highlighting the option near the bottom of the menu that says “Edit as HTML”

    Swap out that PHP code I wrote earlier with the shortcode like below:

    <p><a href="https://ceforcivil.magicbrain.pt/site/ficha-de-inscricao/?title=[CF7_get_current_var key='title']">INSCRI??O</a></p>
    Screenshot of the block editor in WordPress with the paragraph block in HTML editor mode, highlighting the use of a DTX shortcode in the URL as a value for a parameter.

    You can click the “Edit Visually” button when done so it can show the pretty link. It won’t work in the backend, but once you publish it or preview the draft, you can see it work on the frontend as expected, click it, and you should see the URL at the top with the former page’s title in the query and then prepopulated in the form!

    Screenshot of a page called Demo with a link that has ?title=Demo in it, showing the shortcode grabbed the page’s title.
    Screenshot of the page with the form that shows that the ?title=Demo worked and the page’s name Demo successfully prepopulated as Course Title.
    Thread Starter Luis Correia

    (@simplewebpt)

    Many thanks for the reply.
    It works perfectly and resolves the situation.
    Thank you for the quick response, I really appreciate it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Get Previous title Post’ is closed to new replies.