如何在if else条件下动态添加/更改字段?

时间:2017-05-01 05:21:38

标签: php codeigniter

这里我在表单中有很多输入字段,它们运行良好。现在,我想根据property_type添加新的输入框及其标签,这个页面已经存在。

现在,请建议我如何在该表单中添加新字段。

这是我的表格代码

     <div class="dashboard_price_left">

    <h3>
        <?php
        if ($this->lang->line('BasePrice') != '') {
            echo stripslashes($this->lang->line('BasePrice'));
        } else
            echo "Base Price";

        ?>
    </h3>

    <p>
        <?php
        if ($this->lang->line('Atitleandsummary') != '') {
            echo stripslashes($this->lang->line('Atitleandsummary'));
        } else
            echo "Set weekly or monthly price guests will see for your listing.";

        ?>
    </p>

</div>
<?php
if ($listDetail->row()->home_type == 'Office') {

} else if ($listDetail->row()->home_type == 'House') {

}

?>
<form id="pricelist" name="pricelist" action="site/product/savePriceList" method="post">
    <div class="dashboard_price_right">

        <label><?php
            if ($this->lang->line('Pernight') != '') {
                echo stripslashes($this->lang->line('Pernight'));
            } else
                echo "Per night";

            ?>
        </label>

        <div class="amoutnt-container">
            <?php if ($currentCurrency == '') { ?>
                <span class="WebRupee"><?php echo $currencyDetail->row()->currency_symbols; ?></span>
            <?php } else { ?>
                <span class="WebRupee"><?php echo $currentCurrency; ?></span>
            <?php } ?>
            <input type="text" id="price" value="<?php
            if ($listDetail->row()->price != '0.00') {
                echo intval($listDetail->row()->price);
            }

            ?>" class="per_amount_scroll"  name="price" onkeypress="return onlyNumbersWithDot(event);" onchange="javascript:Detailview(this,<?php echo $listDetail->row()->id; ?>, 'price');" />
            <input type="hidden" id="id" name="id" value="<?php echo $listDetail->row()->id; ?>" />
        </div>
        <div class="dashboard_currency">
            <label><?php
                if ($this->lang->line('Currency') != '') {
                    echo stripslashes($this->lang->line('Currency'));
                } else
                    echo "Currency";

                ?>
            </label>
            <div class="select select-large select-block">
                <select name="currency" id="currency" onchange="javascript:Detailview(this,<?php echo $listDetail->row()->id; ?>, 'currency');get_currency_symbol(this)" >
                    <!--<option value="">select</option>-->

                    <?php foreach ($currencyDetail->result() as $currency) { ?>
                        <option value="<?php echo $currency->currency_type; ?>" <?php if ($listDetail->row()->currency == $currency->currency_type) echo 'selected="selected"'; ?>><?php echo $currency->currency_type; ?></option>
                    <?php } ?>
                </select>
            </div>
        </div>
    </div>
</form>

以下是我的房产价格表格

enter image description here

注意:以下有两种类型的属性:

1。办公室

2。房子

基于这些属性,我想在表单中添加更多字段。

请建议我,提前致谢:)

1 个答案:

答案 0 :(得分:0)

你可以根据条件改变它并传递隐藏的字段,表明你的办公室或房子。

<?php
if ($listDetail->row()->home_type == 'Office') 
{
<input type="hidden" name="home_type" value="Office" />
<input type="text" name="per_day" value="" />
<input type="text" name="half_day" value="" />
<input type="text" name="per_hour" value="" />
} 
else if ($listDetail->row()->home_type == 'House') 
{
<input type="hidden" name="home_type" value="House" />
<input type="text" name="per_night" value="" />
<input type="text" name="per_day" value="" />
<input type="text" name="per_hour" value="" />
}
?>