2017-03-03 1 views
0

나는 cake 3.0을 사용하여 응용 프로그램을 개발 중입니다. 사용자가 자신의 세부 정보를 수정하려고하면 양식이 여러 번 제출 될 때마다 성공 메시지가 여러 번 표시됩니다. 나는 케이크 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를 추가하여 중복 제출을 감지 할 수 있지만 첫 번째 옵션은 트릭을 수행해야합니다.