2017-03-03 23 views
0

我使用蛋糕php 3.0來開發應用程序。當用戶嘗試編輯他的詳細信息時,多次提交表單多次顯示成功的Flash消息。我正在使用蛋糕php表單生成器。這裏是我的代碼蛋糕php 3.0中的多個表單提交

<?= $this->Form->create('Project'); ?> 
    <?= $this->Html->link(' キャンセル 編集', array('action' => 'view', $project['id']), array('class' => 'btn btn-default pull-right', 'style' => 'margin: 5px 14px 0 0', 'rule' => 'button')); ?> 
    <?= $this->Form->button(__(' 保存 '), array('class' => 'btn btn-default pull-right', 'style' => 'margin: 5px 14px 0 0 ', 'id' => 'edit', 'onsubmit'=> 'disable()')); ?> 
    <h3 style="font-weight:bold; padding-left:10px; margin: 10px 0 20px;"> 案件基本情報 </h3> 

    <section id="unseen"> 
    <div class="col-sm-12" role="complementary"> 
    <div class="panel panel-default" > 
    <div class="panel-body table-responsive" style ="padding:0px !important"> 
     <table class="table table-bordered table-condensed f11 table-nowrap " style ="margin:0px; "> 
     <tbody> 
      <tr> 
      <td width="23%" class="numeric cell-bg">案件ID</td> 
      <td class="numeric"> 
       <?php if ($project['survey_status'] == $this->Comm->DbConst('PROJECT_SURVEY_STATUS_NEW')) { ?> 
       <?= $this->Form->input('survey_id', array('type' => 'text', 'class' => 'form-control', 'required' => true, 'label' => false, 'value' => __($project['survey_id']))) ?> <div style="color:red;"><?php 
       if (!empty($errors['survey_id'])) { 
        echo reset($errors['survey_id']); 
       } 
       ?></div></td> 
      <?php } else { ?> 
        <?= $this->Form->input('survey_id', array('type' => 'text', 'class' => 'form-control', 'required' => false, 'label' => false, 'disabled' => true, 'value' => __($project['survey_id']))) ?> </td> 
       <?php } ?> 
      <td width="30%" colspan="2" class="numeric cell-bg">運用者名</td> 
      </tr> 
      <tr> 
      <td class="numeric cell-bg">案件名</td> 
      <td class="numeric"><?= $this->Form->input('title', array('type' => 'text', 'class' => 'form-control', 'required' => true, 'label' => false, 'value' => __($project['title']))) ?> <div style="color:red;"><?php 
       if (!empty($errors['title'])) { 
        echo reset($errors['title']); 
       } 
       ?></div></td> 
      <td colspan="2" rowspan="3" class="numeric"> 
       <div class="selectRow">    
       <select class="operator form-control" style="max-width:100%; " name="operator[]" data-placeholder="運用者選択" multiple required > 
        <?php foreach ($operators as $operator) { ?> 
        <option value=<?php 
        echo $operator['id'] . ":" . $operator['username']; 
        ?> selected><?php echo h($operator['username']); ?></option> 
          <?php } ?> 
       </select> 
       <div style="color:red;"><?php 
        if (!empty($errors['operator'])) { 
        echo reset($errors['operator']); 
        } 
        ?></div> 
       </div> 
      </td> 
      </tr> 
      <tr> 
      <td colspan="2" class="numeric cell-bg"><strong>顧客情報</strong></td> 
      </tr> 
      <tr> 
      <td class="numeric cell-bg">會社名</td> 
      <td class="numeric"><?= $this->Form->input('company_name', array('type' => 'text', 'class' => 'form-control', 'required' => true, 'label' => false, 'value' => __($project['company_name']))) ?> <div style="color:red;"> <?php 
       if (!empty($errors['company_name'])) { 
        echo reset($errors['company_name']); 
       } 
       ?></div></td> 
      </tr> 
      <tr> 
      <td class="numeric cell-bg">部署名</td> 
      <td class="numeric"><?= $this->Form->input('department_name', array('type' => 'text', 'class' => 'form-control', 'required' => true, 'label' => false, 'value' => __($project['department_name']))) ?> <div style="color:red;"><?php 
       if (!empty($errors['department_name'])) { 
        echo reset($errors['department_name']); 
       } 
       ?></div></td> 
      <td colspan="2" class="numeric cell-bg">參照者 </td> 
      </tr>  
      <tr> 
      <td class="numeric cell-bg">管理者氏名</td> 
      <td class="numeric"><?= $this->Form->input('name', array('type' => 'text', 'class' => 'form-control', 'required' => true, 'label' => false, 'value' => __($project['name']))) ?><div style="color:red;"> <?php 
       if (!empty($errors['name'])) { 
        echo reset($errors['name']); 
       } 
       ?></div></td> 
      <td colspan="2" rowspan="3" class="numeric"> 
       <div class="selectRow">    
       <select class="viewer form-control" style="max-width:100%;" name="viewer[]" data-placeholder="參照者選択" multiple required > 
        <?php foreach ($viewers as $viewer) { ?> 
        <option value=<?php echo $viewer['id'] . ":" . $viewer['username']; ?> selected><?php echo h($viewer['username']); ?></option> 
        <?php } ?> 
       </select>    
       <div style="color:red;"><?php 
        if (!empty($errors['viewer'])) { 
        echo reset($errors['viewer']); 
        } 
        ?></div> 
       </div> 
      </td> 
      </tr> 
      <tr> 
      <td class="numeric cell-bg">管理者アカウント</td> 
      <td class="numeric"><?= $this->Form->input('air_id', array('type' => 'text', 'class' => 'form-control', 'required' => true, 'label' => false, 'value' => __($project['air_id']))) ?> <div style="color:red;"><?php 
       if (!empty($errors['air_id'])) { 
        echo reset($errors['air_id']); 
       } 
       ?></div></td> 
      </tr> 
      <tr> 
      <td class="numeric cell-bg">管理者メールアドレス</td> 
      <td class="numeric"><?= $this->Form->input('email', array('type' => 'email', 'class' => 'form-control', 'required' => true, 'label' => false, 'value' => __($project['email']))) ?><div style="color:red;"> <?php 
       if (!empty($errors['email'])) { 
        echo reset($errors['email']); 
       } 
       ?></div></td> 
      </tr> 

     </tbody> 
     </table> 
    </div> 
    </div> 
</div> 

形式 - >結束()?>

如何防止多重提交。無論是使用蛋糕PHP的功能或使用任何其他方法。我已經嘗試加載csrf組件,但這不適合我。

+0

請發佈完整的表格或完整的視圖文件。 – Aarrbee

回答

0

我做什麼來防止多個表單提交,是在提交和操作完成它的工作後,我重定向到另一個url或相同。

<?php 

public function add(){ 
    //Grab data and validate it 
    if($this->save($data)){ 
     $this->Flash->set(...); 
     return $this->redirect(array('action', 'index')); // redirect to prevent resubmission 
    } 
    //Do other processing ... 

} 
+0

我已經將其重定向到其他頁面,然後重新提交 –

+1

您可以發佈操作代碼嗎 –

0

根據我的經驗,重複表單提交通常總是雙擊......等。只需提交<button>即可調用禁用該按鈕的JavaScript函數,然後提交表單以防止發生這種情況。

你可以考慮在隱藏字段中爲表單添加一個唯一的ID,以檢測任何重複的提交仍然通過,但第一個選項應該做的伎倆。