简体   繁体   中英

I want to get value from fields loop .How can I do?

I'm using joomla and I have begun to develop a web app, I want to get values from form fields. Normally I use $_POST but this page didn't work.

This is my default.php >>>

<?php
defined('_JEXEC') or die;

JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
?>

<div class="item" <?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
    <h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1>
<?php endif; ?>

<form id="add-item" action="<?php echo JRoute::_('index.php?option=com_stationery&task=item.save'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
<?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?>
    <?php $fields = $this->form->getFieldset($fieldset->name);?>
    <?php if (count($fields)):?>
        <fieldset>
        <?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.
        ?>
            <legend><?php echo JText::_($fieldset->label);?></legend>
        <?php endif;?>
            <dl>
        <?php foreach($fields as $field):// Iterate through the fields in the set and display them.?>
            <?php if ($field->hidden):// If the field is hidden, just display the input.?>
                <?php echo $field->input;?>
            <?php else:?>
                <dt>
                    <?php echo $field->label; // Show label for registor ?>
                    <?php if (!$field->required && $field->type!='Spacer'): ?>

                    <?php endif; ?>
                </dt>
                <dd><?php echo ($field->type!='Spacer') ? $field->input : "&#160;"; ?></dd>
            <?php endif;?>
        <?php endforeach;?>
            </dl>
        </fieldset>
    <?php endif;?>
<?php endforeach;?>
        <div>
            <button name="save" type="submit" class="btn btn-success" class="validate"><?php echo JText::_('Save');?></button>
            <?php echo JText::_('or');?>
            <a class="btn btn-danger" href="<?php echo JRoute::_('/stationery/index.php/add-items');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
            <input type="hidden" name="option" value="com_stationery" />
            <input type="hidden" name="task" value="item.save" />
            <?php echo JHtml::_('form.token');?>

        </div>
    </form>
<script>

This is loop from field.xml to show each field. I want to get value in that inputbox. now I can get to javascript variable but I can't use to save in my table. I want php variable ($....). How can I get it? Please help me. Thank you

In Joomla 2.5+ you could use JRequest, but since it's deprecated you should:

JFactory::getApplication()->input->get...

however looking at your code there may be a simpler approach just bind the input to the table model

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM