• I have to fields 1 is input text field and 1 is dropdown field (dropdown has 5 fields redirecting to my website pages according to my selection form dropdown if i select field a it redirect me to field a page), now i want to pass my 1st input field value as a text or in a input field to my selected dropdown a page. Here is the code i am just facing to not getting input field value to my selected page.

    add_shortcode('tracking_form','tracking_form_callback');
    function tracking_form_callback(){
        ob_start();
        ?>
    <div class="tracking-form">
    <form method="post" id="tracking_form"> 
        
        
    <input id="tracking-field" required="" name="tracking_number" type="text" placeholder="Check Item" />
    <select class="tracking-link" name="tracking-link">
    <option value="">Select Item</option>
    <option value="example.com/item-a-page">item a page</option>
    <option value="example.com/item-b-page">item b page</option>
    <option value="example.com/item-c-page">item c page</option>
            </select>
    
        <button type="submit" class="track_btn">Track</button>
    </form>
    </div>
    <?php
        return ob_get_clean();
    }
    /**** inner items field shortcode ***/
    add_shortcode('inner_courier_form','inner_courier_call_back');
    function inner_courier_call_back(){
        ob_start();
        if($_POST){
    
            $value= $_POST['tracking_number'];
    }
    ?>
    <div class="track-number">
    <input id="wpforms-131-field_0" required="" type="text" placeholder="Check Item" value="<?php echo $value ;?>">
    </div>
    <?php
        return ob_get_clean();
    }
    /**** Item script ***/
    add_action('wp_footer','tracking_script_func');
    function tracking_script_func(){
        ?>
    <script typpe="text/javascript">
    var $ = jQuery;
        $(document).ready(function() {
            $("#tracking_form").submit(function(e){
                e.preventDefault();
            var courier_number = $('.tracking-field').val();
               var url = $('.tracking-link').val();
                console.log('submit form' , url);
                   window.location.href = url; 
    
            });
    });
    </script>
    <?php
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • You’d need to use JavaScript to add the value from the text field to the URL that you’re redirecting to.

    This is not tested, but something like this should do what you’re after…

    var url = $('.tracking-link').val() + '?tracking-field=' + $('tracking-field').val ();

    Thread Starter jamesandi

    (@jamesandi)

    Thanks for this, i have sorted it out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pass Value of input field on button click from one page to another page Input fi’ is closed to new replies.