0

我可以在 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 中添加这个表单。我的表单是:

<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

4 回答 4

4
<?php
 //your php code here
 ?>

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

 <?php
 //more php code
 ?>
于 2013-09-16T07:58:27.117 回答
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'>";
}

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

于 2013-09-16T07:57:42.237 回答
0
<?php
  some php code
  echo "<div class='something'>"
?>php
于 2013-09-16T07:59:57.480 回答
0

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

于 2013-09-16T08:00:16.350 回答