Search code examples
phphtmlhref

How do I pass php variables and textarea values using a href?


I have some variables stored using php and an html textarea. I would like the value from the textarea (whatever user types in) to be stored in a variable $options and pass all of the variables from the same page using . I am getting stuck on how to combine the value from the textarea with the php variables' values. This is the code I have so far:

$price = $_GET['price'];
$title = $_GET['title'];
$retailer = $_GET['retailer'];

<textarea rows="3" id="textarea" class="input-xlarge" placeholder="Size, color, style, etc" name ="options"></textarea>

<a href = "viewcart.php?retailer=<?php echo $retailer?>" class="btn btn-success" type="submit"><i class="icon-shopping-cart icon-white"></i>  Add to Cart</a>

How do I combine the three variables together?


Solution

  • UPDATE

    Use this code, you have to add some javascript code to get value of text area.

    $price = $_GET['price'];
    $title = $_GET['title'];
    $retailer = $_GET['retailer'];
    
    <textarea rows="3" id="textarea" class="input-xlarge" placeholder="Size, color, style, etc" name ="options"></textarea>
    
    <script language="javascript">
    function test()
    {
        var val=document.getElementById("textarea").value;  
        var hrf="viewcart.php?retailer=<?php echo $retailer?>&price=<?php echo $price; ?>&title=<?php echo $title; ?>&option="+val;
        document.getElementById("a_link").href=hrf;
    }
    </script>
    <a href ="#" id="a_link" onclick="test();" class="btn btn-success" type="submit"><i class="icon-shopping-cart icon-white"></i>  Add to Cart</a>
    

    Update your code with my code and test it.