Support » Fixing WordPress » redirect button to url created with variables

  • Resolved ericjs61



    I have this code:
    <form action=”; method=”post”>
    <input type=”submit”>

    However, what I want to do is replace “; with a variable like:
    $regionURL = “” . $current_user_id . “<br>”;

    <form action=”‘regionURL'” method=”post”>
    <input type=”submit”>

    When a user clicks on the button, they are redirected to a url where the last part of the url is their user id.

    I am using Elementor </> HTML Element.

    How can I write the code to do what I want? Is this even possible?

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    Just echo out what you want from a PHP block entered into your form HTML. Your form HTML must be on a .php file of some sort. You cannot put this in an Elementor editor.
    <form action="<?php echo '' . get_current_user_id() . '/'; ?>" method="post">

    One way to get custom PHP data into page content is by shortcode, which can be input into the editor. Another is by a custom page template.

    Probably too pedantic, but here it goes: When the user clicks a form submit button, the form doesn’t “redirect” the user. The form simply submits a request directly to that URL. I know you meant the user is redirected from the current page, but that is not what a “redirect” is. When the request reaches the server, the requested file does not exist, so the request is rewritten to WP. In processing the request, WP might do further redirects. But the initial URL on your form is not considered a redirect.

    Just sayin’ 🙂

    Thank you so much!! With using the plugin Woody Snippet – I was able to create this code that did so much more. I learned that I can pass PHP code from the server to the client(html) using <?php and ?> here is the new code that does so much more:

    global $wpdb;
    $current_user_id = get_current_user_id();
    $todayA = date(“Y/m/d”);
    $startB = date(‘2019/01/31’);
    $endC = date(‘2019/03/17’);

    if (($startB < $todayA) and ($todayA < $endC)) {
    $Play = “Ready to Play”;
    $url = “; . $current_user_id . “/32”;
    $GoPlay = “submit”;
    } elseif ($todayA < $startB)
    $Play = “Coming Soon”;
    $url = “;;
    $GoPlay = “button”;
    } else {
    $Play = “Closed”;
    $url = “;;
    $GoPlay = “button”;


    <form action=”<?php echo $url; ?>” method = “post”>
    <input type=”<?php echo $GoPlay; ?>” value=”<?php echo $Play; ?>”>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘redirect button to url created with variables’ is closed to new replies.