多个表单未正确提交

时间:2017-10-05 21:37:47

标签: javascript php html forms opencart

我在OpenCart MVC工作,我有一个页面,其中包含一个名为campaign的主窗体。有一个称为组件的辅助表单。组件表单允许自己的多个实例(单击添加另一个组件显示)。我们的想法是,广告系列可以包含无限的组件,并且在提交时,广告系列信息将被写入广告系列表格,组件信息将被写入组件表格。好吧,这没有发生。目前我填写两份表格并提交。广告系列表单的信息将写入表格。但是在组件表中创建了一条新记录,但它全部为空白。为什么没有添加这些值?此外,其他组件似乎根本没有写入。因此,如果您启动一个广告系列并添加三个组件,则只提交一个新的(空白)记录将写入组件。

MODEL:

public function addCampaign($data) {

        $this->db->query("INSERT INTO " . DB_PREFIX . "campaigns SET campaign_name = '" . $this->db->escape($data['campaign_name']) . "', campaign_giving_goal = '" . (float)$data['campaign_giving_goal']
        . "', code = '" . $this->db->escape($data['code']) . "', campaign_active = '" . $this->db->escape($data['campaign_active']) . "', campaign_giving_count_goal = '" . (float)$data['campaign_giving_count_goal']
        . "', campaign_owner = '" . $this->db->escape($data['campaign_owner']). "', date_beginning = '" . $this->db->escape($data['date_beginning']). "', date_ending = '" . $this->db->escape($data['date_ending']). "'");

        $this->cache->delete('campaign');

        return $campaign_id;
    }

    public function addComponent($data) {

        $this->db->query("INSERT INTO " . DB_PREFIX . "campaign_components SET component_name = '" . $this->db->escape($data['component_name']) . "', component_date = '" . $data['component_date']
         . "', component_owner = '" . $this->db->escape($data['component_owner']). "', campaign_code = '" . $this->db->escape($data['campaign_code']) . "'");

        $this->cache->delete('campaign');

        return $campaign_id;
    }

CONTROLLER:

public function add() {
        $this->load->language('campaigns/campaign');

        $this->document->setTitle($this->language->get('heading_title'));

        $this->load->model('campaigns/campaign');

        if (($this->request->server['REQUEST_METHOD'] == 'POST')) {

            $this->model_campaigns_campaign->addCampaign($this->request->post);
            $this->model_campaigns_campaign->addComponent($this->request->post);
            $this->session->data['success'] = $this->language->get('text_success');
            $url = '';

            if (isset($this->request->get['order'])) {
                $url .= '&order=' . $this->request->get['order'];
            }

            if (isset($this->request->get['page'])) {
                $url .= '&page=' . $this->request->get['page'];
            }

            $this->response->redirect($this->url->link('campaigns/campaign', 'token=' . $this->session->data['token'] . $url, true));
        }

        $this->getForm();

    }

查看:

<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-campaign" action="<?php echo $action; ?>" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary" onclick="submitForms()"><i class="fa fa-save"></i></button>
        <a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a>
      </div>
      <h1><?php echo $heading_title; ?></h1>
      <ul class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
        <?php } ?>
      </ul>
    </div>
  </div>

  <div class="container-fluid">
    <?php if ($error_warning) { ?>
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_form; ?></h3>

      </div>
      <div class="panel-body">
        <form method="post" action="<?php echo $action; ?>" enctype="multipart/form-data" id="form-campaign" class="form-horizontal">
          <div class="tab-content">
            <div class="tab-pane active" id="tab-general">

                <?php foreach ($languages as $language) { ?>
                <div class="tab-pane" id="language<?php echo $language['language_id']; ?>">
                  <div class="form-group">

                    <div class="col-sm-5 col-sm-push-1 form-group required">
                      <label class="control-label" for="input-campaign-name"><?php echo $entry_name; ?></label>
                      <input type="text" name="campaign_name" placeholder="<?php echo $entry_name; ?>" id="input-campaign-name" class="form-control" value="<?php echo $campaign_name; ?>" />
                      <?php if (isset($error_name[$language['language_id']])) { ?>
                      <div class="text-danger"><?php echo $error_name[$language['language_id']]; ?></div>
                      <?php } ?>
                    </div>
                    <div class="col-sm-5 col-sm-push-1 form-group required">
                        <label class="control-label" ><?php echo $entry_owner; ?></label>
                        <select name="campaign_owner" id="campaign_owner" value="<?php echo $campaign_owner; ?>">
                        <?php foreach ($users as $user) { ?>
                            <option value="<?php echo $user['username']; ?>"><?php echo $user['username']; ?></option>
                        <?php } ?>
                        </select>
                    </div>
                    <div class="col-sm-5 col-sm-push-1 form-group required">
                      <label class="control-label" for="input-campaign-goal"><?php echo $entry_goal; ?></label>
                      <input type="text" name="campaign_giving_goal" placeholder="<?php echo $entry_goal; ?>" id="input-campaign-goal" class="form-control" value="<?php echo $campaign_giving_goal; ?>" />
                      <?php if (isset($error_name[$language['language_id']])) { ?>
                      <div class="text-danger"><?php echo $error_name[$language['language_id']]; ?></div>
                      <?php } ?>
                    </div>
                    <div class="col-sm-5 col-sm-push-1 form-group required">
                      <label class="control-label" for="input-campaign-goal"><?php echo $entry_goal_count; ?></label>
                      <input type="text" name="campaign_giving_count_goal" placeholder="<?php echo $entry_goal_count; ?>" id="input-campaign-goal-count" class="form-control" value="<?php echo $campaign_giving_count_goal; ?>" />
                      <?php if (isset($error_name[$language['language_id']])) { ?>
                      <div class="text-danger"><?php echo $error_name[$language['language_id']]; ?></div>
                      <?php } ?>
                    </div>
                    <div class="col-sm-5 col-sm-push-1 form-group required">
                      <label class="control-label" for="input-date-beginning"><?php echo $entry_campaign_start_date; ?></label>
                        <div class="input-group date required">
                          <input type="text" name="date_beginning"  placeholder="<?php echo  $entry_date; ?>" data-date-format="YYYY-MM-DD" id="input-date-beginning" class="form-control" value="<?php echo $date_beginning; ?>" readonly />
                          <span class="input-group-btn">
                          <button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
                          </span>
                    </div>
                    <?php if (isset($error_date_starting)) { ?>
                      <label class="text-danger"><?php echo $error_date_starting; ?></label>
                    <?php } ?>
                  </div>
                  <div class="col-sm-5 col-sm-push-1 form-group required">
                    <label class="control-label" for="input-date-ending"><?php echo $entry_campaign_end_date; ?></label>
                      <div class="input-group date required">
                      <input type="text" name="date_ending"  placeholder="<?php echo  $entry_campaign_end_date; ?>" data-date-format="YYYY-MM-DD" id="input-date-ending" class="form-control" value="<?php echo $date_ending; ?>" readonly />
                      <span class="input-group-btn">
                      <button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
                      </span>
                    </div>
                    <?php if (isset($error_date_starting)) { ?>
                      <label class="text-danger"><?php echo $error_date_starting; ?></label>
                    <?php } ?>
                  </div>

                  <div class="col-sm-5 col-sm-push-1 form-group required">
                    <label class="control-label" for="input-code"><?php echo $entry_code; ?></label>
                      <div class="input-code required">
                      <input type="text" name="code" value="<?php echo $code; ?>" placeholder="<?php echo $code; ?>" id="input-code" class="form-control" readonly />
                    </div>
                    <?php if (isset($error_date_starting)) { ?>
                      <label class="text-danger"><?php echo $error_code; ?></label>
                    <?php } ?>
                  </div>

                  <div class="col-sm-5 col-sm-push-1 form-group required">
                    <label class="control-label" for="input-active"><?php echo $entry_active; ?></label>
                    <select name="campaign_active" id="input-"active" class="form-control">
                      <option value="*"><?php echo $text_active; ?></option>
                      <?php if ($filter_campaign_active) { ?>
                      <option value="1" selected="selected"><?php echo $text_yes; ?></option>
                      <?php } else { ?>
                      <option value="1"><?php echo $text_yes; ?></option>
                      <?php } ?>
                      <?php if (!$filter_campaign_active && !is_null($filter_campaign_active)) { ?>
                      <option value="0" selected="selected"><?php echo $text_no; ?></option>
                      <?php } else { ?>
                      <option value="0"><?php echo $text_no; ?></option>
                      <?php } ?>
                    </select>
                  </div>
                  </div>

                                </div>

                </div>
              </div>
              <?php } ?>

        </form>
        </div>
  </div>
            </div>

      <button class="btn btn-primary" id="launch"><?php echo $text_add_component ?></button>
<div class="wrapper">
          <div class="panel panel-default" id="add-components">

            <div class="panel-heading">
              <h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_add_component; ?></h3>

            </div>
            <div class="panel-body" id="addon">
              <form method="post" enctype="multipart/form-data" id="form-components" class="form-horizontal" action="<?php echo $action; ?>">

                <div class="tab-content">
                  <div class="tab-pane active" id="tab-general">

                      <?php foreach ($languages as $language) { ?>
                      <div class="tab-pane" id="language<?php echo $language['language_id']; ?>">
                        <div class="form-group required">
                          <div class= "row">
                          <div class="col-sm-8 col-sm-push-1 form-group required" >
                            <label for="input-name<?php echo $language['language_id']; ?>"><?php echo $entry_name; ?></label>
                            <input type="text" name="component_name" placeholder="<?php echo $entry_name; ?>" id="input-name<?php echo $language['language_id']; ?>" class="form-control" />

                            <?php if (isset($error_name[$language['language_id']])) { ?>
                            <div class="text-danger"><?php echo $error_name[$language['language_id']]; ?></div>
                            <?php } ?>
                          </div>
                          <div class="col-sm-2 col-sm-push-1 form-group required">
                            <div class="campaign-group form-group">

                                  <div class="dropdown">
                                    <button class="btn btn-primary pull-left dropdown-toggle" type="button" id="button-type" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><?php echo $text_filter_type;?><span class="caret"></span></button>
                                    <ul class="campaign-form-type dropdown-menu">
                                      <li class="campaign-dropdown-list">Direct Mail</li>
                                      <li class="campaign-dropdown-list">Email</li>
                                      <li class="campaign-dropdown-list">Event</li>
                                      <li class="campaign-dropdown-list">Text Message</li>
                                      <li class="campaign-dropdown-list">Letter</li>
                                      <li class="campaign-dropdown-list">Postcard</li>
                                    </ul>
                                  </div>
                            </div>
                          </div>
                        </div>
                        <div class="row">
                          <div class="col-sm-4 col-sm-push-1 form-group required">
                          <label class="control-label" for="input-date-beginning"><?php echo $entry_campaign_start_date; ?></label>
                            <div class="input-group date required">
                              <input type="text" name="date_beginning"  placeholder="<?php echo  $entry_date; ?>" data-date-format="YYYY-MM-DD" id="input-date-beginning" class="form-control" />
                              <span class="input-group-btn">
                              <button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
                              </span>
                            </div>
                            <?php if (isset($error_date_starting)) { ?>
                              <label class="text-danger"><?php echo $error_date_starting; ?></label>
                            <?php } ?>
                          </div>
                          <div class="col-sm-4 col-sm-push-1 form-group required">
                              <label class="control-label" ><?php echo $entry_owner; ?></label>
                              <select name="campaign_owner" id="component_owner">
                              <?php foreach ($users as $user) { ?>
                                  <option value="<?php echo $user['username']; ?>"><?php echo $user['username']; ?></option>
                              <?php } ?>
                              </select>
                          </div>
                          <div class="col-sm-5 col-sm-push-1 form-group required">
                            <!--label class="control-label" for="input-code"><?php echo $entry_code; ?></label-->
                              <div class="input-code required">
                              <input type="text" name="code" value="<?php echo $code; ?>" placeholder="<?php echo $code; ?>" id="input-code" class="form-control" readonly />
                            </div>
                            <?php if (isset($error_date_starting)) { ?>
                              <label class="text-danger"><?php echo $error_code; ?></label>
                            <?php } ?>
                          </div>
                        </div>


                                        </div>

                                    </div>

                    </div>
                    </div>
                    <?php } ?>
                  </div>
                    </form>
</div>

                </div>
                <div class="cancel-save">
                  <button type="submit" form="form-campaign" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary" onclick="submitForms(0)"><i class="fa fa-save"></i></button>
                  <a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a>
                </div>
</div>

        </div>
  <script type="text/javascript" src="view/javascript/summernote/summernote.js"></script>
  <link href="view/javascript/summernote/summernote.css" rel="stylesheet" />
    <script type="text/javascript" src="view/javascript/summernote/opencart.js"></script>


  </script>

  <script type="text/javascript"><!--
$('#input-code').on('keyup', function() {
  $('#input-example1').val('<?php echo $store; ?>?tracking=' + $('#input-code').val());
  $('#input-example2').val('<?php echo $store; ?>index.php?route=common/home&tracking=' + $('#input-code').val());
});

$('#input-code').trigger('keyup');
//--></script>

  <script type="text/javascript">
  document.getElementById('launch').onclick = function() {
        var addOnDiv = document.getElementById('addon');
    var container = document.getElementById('add-components')
        var clonedNode = addOnDiv.cloneNode(true);
          container.appendChild(clonedNode );
      }


  </script>

  <script type="text/javascript"><!--
  submitForms = function(){
    document.getElementById("form-campaign").submit();
    document.getElementById("form-components").submit();
}
</script>



  <script type="text/javascript"><!--
$('.date').datetimepicker({
    formatDate:'yyyy-mm-dd',
        pickTime: false
});

$('.time').datetimepicker({
    pickDate: false,
    icons: {
            up: 'fa fa-chevron-up',
            down: 'fa fa-chevron-down',
            },
});

$('.datetime').datetimepicker({
    pickDate: true,
    pickTime: true
});
//--></script>
  <script type="text/javascript"><!--
$('#language a:first').tab('show');
$('#option a:first').tab('show');
//--></script></div>
<?php echo $footer; ?>

0 个答案:

没有答案