2012-04-18 8 views
0

Jsヘルパーでデータベースにデータを送信するための簡単なフォームを作成しようとしています。ここで図である。CakePHP 2.1とAjaxフォームがJsヘルパーと一緒にサブミットする

<div class="modal hide fade" id="modal-note-add"> 
    <div class="modal-header"> 
    <a class="close" data-dismiss="modal">×</a> 
    <h3>Add Note</h3> 
    </div> 
    <div id="modal-note-add-body" class="modal-body"> 
    <?php echo $this->Form->create('Note', array('action' => 'addIframe')); ?> 
    <?php 
    echo $this->Form->input('id'); 
    echo $this->Form->input('project_id', array('type' => 'hidden')); 
    echo $this->Form->input('user_id', array('type' => 'hidden', 'value' => $this->Session->read('Auth.User.id'))); 
    echo $this->Form->input('date', array('type' => 'text', 'value' => date('Y-m-d'), 'class' => 'datepicker')); 
    echo $this->Form->input('note_type_id', array('type' => 'hidden', 'value' => 1)); 
    echo $this->Form->input('comment', array('class' => 'tinymce span4')); 
    ?> 
    </div> 
    <div class="modal-footer"> 
    <?php 
    echo $this->Js->submit('Save', array('url' => '/notes/addIframe', 'update' => '#content', 'class' => 'btn btn-primary btn-large')); 
    echo $this->Form->end(); 
    ?> 
    </div> 
</div> 

出力:

<div class="modal hide fade in" id="modal-note-add" style="display: block; "> 
    <div class="modal-header"> 
    <a class="close" data-dismiss="modal">×</a> 
    <h3>Add Note</h3> 
    </div> 
    <div id="modal-note-add-body" class="modal-body"> 
    <form action="/notes/addIframe" id="NoteAddIframeForm" method="post" accept-charset="utf-8"> 
    <div style="display:none;"> 
     <input type="hidden" name="_method" value="POST"> 
    </div> 
    <input type="hidden" name="data[Note][id]" id="NoteId"> 
    <input type="hidden" name="data[Note][project_id]" id="NoteProjectId" value="11095"> 
    <input type="hidden" name="data[Note][user_id]" value="1" id="NoteUserId"> 
    <div class="input text"> 
     <label for="NoteDate">Date</label> 
     <input name="data[Note][date]" value="2012-04-18" class="datepicker hasDatepicker" type="text" id="NoteDate"> 
    </div> 
    <input type="hidden" name="data[Note][note_type_id]" value="1" id="NoteNoteTypeId"> 
    <div class="input textarea"> 
     <label for="NoteComment">Comment</label> 
     <textarea name="data[Note][comment]" class="tinymce span4" cols="30" rows="6" id="NoteComment"></textarea> 
    </div> 
    </form> 
    </div> 
    <div class="modal-footer"> 
    <div class="submit"><input class="btn btn-primary btn-large" id="submit-1899329211" type="submit" value="Save"></div> 
    </div> 
</div> 
.... 
<script type="text/javascript"> 
//<![CDATA[ 
$(document).ready(function() {$("#submit-1899329211").bind("click", function (event) {$.ajax({data:$("#submit-1899329211").closest("form").serialize(), dataType:"html", success:function (data, textStatus) {$("#content").html(data);}, type:"post", url:"\/notes\/addIframe"}); 
return false;});}); 
//]]> 
</script> 

コントローラのアクション:

public function addIframe() { 
    if ($this->request->is('ajax')) { 
    $this->Note->save($this->request->data); 
    if ($this->Note->save($this->request->data)) { 
     $this->Session->setFlash(__('The project note has been saved.', true), 'flash_success'); 
    } else { 
    $this->Session->setFlash(__('The note could not be saved. Please, try again.', true), 'flash_error'); 
    } 
    } 
} 

結果の提出は、データベース内のレコードを作成していないが、私のフォームからの値のどれも渡されます。どんな洞察?

答えて

関連する問題