Jump to content

How to output a large block of html code with passed variables?


ttmt

Recommended Posts

How to input a large block of html code with passed variables?

 

Hi all

 

I have a large block of html code that is part of the paypal add to cart button.

 

I need to add this code a number of times with different variables for each one.

 

I want to have this block of html in a separate function that I can then call and pass in the variables in.

 

PHP

<?php
  function item($name, $number){
    echo "
    <div class='product'>
      <h2>Product Name</h2>
      <form target='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>
      <input type='hidden' name='cmd' value='_cart''>
      <input type='hidden' name='business' value='emailAddress'>
      <input type='hidden' name='lc' value='GB'>
      <input type='hidden' name='item_name' value='".$name."'>
      <input type='hidden' name='item_number' value='".$number."'>
      <input type='hidden' name='button_subtype' value='products'>
      <input type='hidden' name='no_note' value='0'>
      <input type='hidden' name='cn' value='Add special instructions to the seller'>
      <input type='hidden' name='no_shipping' value='2'>
      <input type='hidden' name='add' value='1'>
      <input type='hidden' name='bn' value='PP-ShopCartBF:btn_cart_LG.gif:NonHosted'>
      <table>
      <tr><td><input type='hidden' name='on0' value='Number of Users'>Number of Users</td></tr><tr><td><select name='os0'>
      <option value='1 - 5'>1 - 5 £0.01</option>
      <option value='6 - 10'>6 - 10 £0.02</option>
      <option value='11 - 20'>11 - 20 £0.03</option>
      <option value='21 - 50'>21 - 50 £0.04</option>
      <option value='51 - 100'>51 - 100 £0.05</option>
      <option value='100+'>100+ £0.06</option>
      </select> </td></tr>
      </table>
      <input type='hidden' name='currency_code' value='GBP'>
      <input type='hidden' name='option_select0' value='1 - 5'>
      <input type='hidden' name='option_amount0' value='0.01'>
      <input type='hidden' name='option_select1' value='6 - 10'>
      <input type='hidden' name='option_amount1' value='0.02'>
      <input type='hidden' name='option_select2' value='11 - 20'>
      <input type='hidden' name='option_amount2' value='0.03'>
      <input type='hidden' name='option_select3' value='21 - 50'>
      <input type='hidden' name='option_amount3' value='0.04'>
      <input type='hidden' name='option_select4' value='51 - 100'>
      <input type='hidden' name='option_amount4' value='0.05'>
      <input type='hidden' name='option_select5' value='100+'>
      <input type='hidden' name='option_amount5' value='0.06'>
      <input type='hidden' name='option_index' value='0'>
      <input class='button' type='image' src='https://www.paypalobjects.com/en_GB/i/btn/btn_cart_LG.gif' border='0' name='submit' alt='PayPal — The safer, easier way to pay online.'>
      <img alt='' border='0' src='https://www.paypalobjects.com/en_GB/i/scr/pixel.gif' width='1' height='1'>
      </form>
    </div>
  
  }
  "
?>

 

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>untitled</title>

<?php
  
  require_once("functions.php");

?>

</head>

<body>
  
  <?php
  
    item($car, $deo);
  
  ?>

</body>
</html>

 

How can I output this html code from a function with passed in variables ?

Link to comment
Share on other sites

seems fine to be, except you closed the function braces BEFORE you closed the echo quotes...

 

instead of:

 

}
"

at the end of the function, try:

";
}

 

then just call the function with:

 

 

require_once("functions.php");
item("the name you want", "the number you want");

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.