在cakephp 1.3中提交后的清晰表格

时间:2013-10-31 22:11:00

标签: javascript jquery forms cakephp

我有一个表单(报表表单),它在页面上多次链接到jquery对话框。我添加了随机字符串以避免交叉发布(提交)。我想在提交后清除表单(ReportContent)字段,并且有一些问题。但是,它在单页面访问提交中工作正常,下面是第二个脚本。请帮忙,...提前谢谢,......克里斯

<?php echo $ajax->form(array('type' => 'post', 'options' => array('model'=>'Group', 'id'=> "submitThis_".$random, 'update' => "updateGroupReport_".$group['Group']['id']. '-'.$random, 'complete' => 'javascript:resetReportGroupForm(' . $random . ');', 'url' => array('controller' => 'groups', 'action' => 'report/'. $group['Group']['id']) ) )); ?>
<?php  echo $this->Form->textarea('Report.content', array('class' => "ReportContent_".$random)); ?>
<?php echo $form->end('Report'); ?>

我想工作,......

<script type="text/javascript">
function resetReportGroupForm($id){
    document.getElementById("submitThis_<?php echo ($random); ?>"), function () {
        $('.ReportContent_<?php echo ($random); ?>').val('');
        };
    };
</script>

这适用于单页访问,...

<script type="text/javascript">
function resetReportGroupForm($id){
    document.getElementById("submitThis_<?php echo ($random); ?>").reset(); 
    }
</script>

2 个答案:

答案 0 :(得分:0)

为什么不尝试这样的事情:

$('form#submitThis_<?php echo $random?>').find("input[type=text], textarea").val("");

我觉得你应该使用jQuery选择器来重置你的表单,而不是......

$('form#yourFormName').submit(function() {
    // process ajax etc

    $(this).find("input[type=text], textarea").val("");
});

答案 1 :(得分:0)

我有另一种方法,......它的工作正常,......如果有人需要,这里是副本,......

<div class="clr"></div>

<div id="updateGroupReport_<?php echo $group['Group']['id'] ?>-<?php echo $random ?>" style="float: left; width: 200px; margin: 5px 0 5px 15px; font-size: 13px; text-align: left;"></div>

<div class="clr"></div>

<div style="float: left; width: 450px; margin: 0 0 20px 15px; font-size: 13px; text-align: left;">

<?php echo $this->Form->create('Group', array('id'=> "FormId_".$random)); ?>
    <?php echo $form->hidden('Report.sender_id', array('value' => $user_object['id'])) ?>

    <p style="font-size: 1.2em; font-weight: normal;">
<?php  echo $this->Form->textarea('Report.content'); ?>
    </p>

    <p>
<?php echo $ajax->submit('Report', array('url'=> array('controller'=>'groups', 'action'=>'report_spam/'. $group['Group']['id']),'id' => "button_".$random, 'update' => "updateGroupReport_".$group['Group']['id']. '-'.$random )); ?>
<?php echo $form->end(); ?>
    </p>

</div>

<script type="text/javascript">
jQuery(document).ready(function() {
    $('#button_<?php echo ($random); ?>').click(function(){
            $(':input', '#FormId_<?php echo ($random); ?>')
        .not(':button, :submit, :reset, :hidden')
        .val('')
        .removeAttr('checked')
        .removeAttr('selected');
        }); 

});
</script>

<div class="clr"></div>