在php内部的div中添加表单

时间:2013-09-16 07:55:38

标签: php

我可以在php内部使用div吗? 例如:

<?php
some php code
<div class="something">
...
...
...
<form ...>
...
...
...
</form>
</div>
?>

编辑: 这是我的代码,它是一个php文件:

<?php
/*
 * @component VM2tags
 * @copyright Copyright (C) 2008-2012 Adrien Roussel
 * @license : GNU/GPL
 * @Website : http://www.nordmograph.com
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
$tag                        = JRequest::getVar('tag');
$products                   = $this->products;
$juri                       = JURI::base();
$doc                        = &JFactory::getDocument();
$doc->addStylesheet($juri.'components/com_vm2tags/assets/css/style.css');
JHTML::_('behavior.tooltip');
$cparams                    =& JComponentHelper::getParams('com_vm2tags');
$vm_itemid                  = $cparams->getValue('vm_itemid');
$vm2tags_itemid             = $cparams->getValue('vm2tags_itemid');
$show_price                     = $cparams->getValue('show_price','1');
$credits                    = $cparams->getValue('credits','0');
echo '<h1>'.JText::_('').' '.$tag.'</h1>';
echo '<div class="pagination" >';
echo '</div>';
function jsonRemoveUnicodeSequences($struct) {
   return preg_replace("/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", json_encode($struct));
}


foreach($products as $product){
    $product_url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$product->virtuemart_product_id.'&virtuemart_category_id='.$product->virtuemart_category_id.'&Itemid='.$vm_itemid);
    echo '<div class="product1" >';
    echo '<div class="product_thumb" >';
        $product_thumb =$product->file_url_thumb;
        if ($product_thumb =='')
            $product_thumb =  'components/com_virtuemart/assets/images/vmgeneral/noimage.gif';
        echo '<a href="'.$product_url.'" ><img src="'.$juri.$product_thumb.'" height="90" alt="img" /></a>';
    echo '</div>';  
        echo '<div class="product_name" >';
        echo '<a href="'.$product_url.'" >'.ucfirst($product->product_name).'</a>';
        echo '</div>';
        if($show_price > 0 ){
            echo '<div class="product_price" >';
            //echo $product->product_price;

            $price_format                   = $this->price_format;
                $symbol                         = $price_format[7];
                $currency_positive_style        = $price_format[11];
                $currency_id                    = $price_format[0];
                $currency                       = $price_format[4];
                $currency_decimal_place         = $price_format[8];

                if($show_price=='1')  // without tax
                    $list_item__product_price = $product->product_price;
                if($show_price=='2')    // with tax(es)
                    $list_item__product_price = Vm2tagsModelproductslist::applytaxes( $product->product_price   , $product->virtuemart_category_id ,  $product->virtuemart_vendor_id)  ;


                    $price_val =  number_format($list_item__product_price , $currency_decimal_place ,   '.' , ' ' );
                    $print_price = str_replace('{number}' ,$price_val ,$currency_positive_style);
                    $print_price = str_replace('{symbol}' ,$symbol ,$print_price);
                echo '<a href="'.$product_url.'" >'. $print_price .'</a>';

            echo '</div>';
        }

                echo '<div class="product-details" >';
        echo JHTML::link (JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$product->virtuemart_product_id.'&virtuemart_category_id='.$product->virtuemart_category_id.'&Itemid='.$vm_itemid), JText::_ ('جزئیات'), array('title' => $product->product_name, 'class' => 'product-details2'));
        echo '</div>';

我想在此处添加表单

    echo '</div>';
}

echo '<div style="clear:both;"></div>';
echo '<div class="pagination" >';
echo $this->pagination->getResultsCounter();
echo $this->pagination->getPagesLinks();
echo $this->pagination->getPagesCounter();
echo '</div>';
if($credits)
    echo '<div style="width:100%;text-align:center;color:#cccccc;font-size:10px;">Powered by Nordmograph.com</div>';

?>

我希望在div class = product1中添加此表单 .my表格是:

<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $products->virtuemart_product_id ?>">
    <div class="addtocart-bar">
            <?php // Display the quantity box ?>
            <!-- <label for="quantity<?php echo $product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
            <span class="quantity-box">
                <input style="display:none;" type="text" class="quantity-input" name="quantity[]" value="1" />
            </span>

            <?php // Display the quantity box END ?>

            <?php // Add the button
            $button_lbl = JText::_('اضافه به کارت');
            $button_cls = ''; //$button_cls = 'addtocart_button';
            if (VmConfig::get('check_stock') == '1' && !$product->product_in_stock) {
                $button_lbl = JText::_('COM_VIRTUEMART_CART_NOTIFY');
                $button_cls = 'notify-button';
            } ?>

            <?php // Display the add to cart button ?>
            <span class="addtocart-button1">
                <input type="submit" name="addtocart" class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
            </span>

        <div class="clear"></div>
        </div>

        <?php // Display the add to cart button END ?>
        <input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
        <input type="hidden" name="option" value="com_virtuemart" />
        <input type="hidden" name="view" value="cart" />
        <noscript><input type="hidden" name="task" value="add" /></noscript>
        <input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
        <?php /** @todo Handle the manufacturer view */ ?>
        <input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
        <input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>

4 个答案:

答案 0 :(得分:4)

<?php
 //your php code here
 ?>

<div class="something">
...
...
...
<form ...>
...
...
...
</form>
</div>

 <?php
 //more php code
 ?>

答案 1 :(得分:3)

简短回答是:是的,你可以。

按如下方式分开:

<?php
    // some code ...
?>
    <div class="something">
    ...
    ...
    ...
    <form ...>
    ...
    ...
    ...
    </form>
    </div>
<?php
    // some more code ..
?>

另一种解决方案是使用HEREDOC语法:

<?php

$html = <<<HTML
    <div class="something">
    ...
    ...
    ...
    <form ...>
    ...
    ...
    ...
    </form>
    </div>
HTML;

echo $html;

?>

或者,如果您的HTML不大,您只需echo

if (something) {
    echo "<div class='something'>";
} else {
    echo "<div class='something else'>";
}

但是,不鼓励使用上述方法,因为它会弄乱您的代码并降低可读性。

答案 2 :(得分:0)

<?php
  some php code
  echo "<div class='something'>"
?>php

答案 3 :(得分:0)

&#39;在PHP内部&#39;浏览器不会知道任何事情,因为PHP是作为预处理完成的。您可以在页面上的任何位置放置PHP代码来修改内容。只要确保您了解自己是在PHP部分内部还是外部工作<?PHP ... ?>。使用编辑器的语法高亮来帮助您。