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

  • Resolved ericjs61

    (@ericjs61)


    Hello,

    I have this code:
    <form action=”http://dev.mitbtennis.com/register/1/1&#8243; method=”post”>
    <input type=”submit”>
    </form>

    However, what I want to do is replace “http://dev.mitbtennis.com/register/1/1&#8221; with a variable like:
    $regionURL = “dev.mitbtennis.com/register/1/” . $current_user_id . “<br>”;

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

    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

    (@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 'http://dev.mitbtennis.com/register/1/' . 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:

    <?php
    global $wpdb;
    get_currentuserinfo();
    $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 = “http://mitbtennis.com/2019/register2play/#/register2play/&#8221; . $current_user_id . “/32”;
    $GoPlay = “submit”;
    } elseif ($todayA < $startB)
    {
    $Play = “Coming Soon”;
    $url = “http://mitbtennis.com/2019/&#8221;;
    $GoPlay = “button”;
    } else {
    $Play = “Closed”;
    $url = “http://mitbtennis.com/2019/&#8221;;
    $GoPlay = “button”;
    }

    ?>

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

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