0

我正在一个 html 文档中尝试两个 form_open。提交第一个必须调用 saveInterview 动作,第二个必须调用 deleteInterview 动作。两种形式都有它们的form_close。但问题是提交第二个表单也会调用 saveInterview 操作而不是 deleteInterview 操作。视图代码如下

<div class="span8" align="right">
    <a href="#EditInterview" role="button" class="btn btn-primary btn-large" data-toggle="modal">Edit</a> <br><br><br></div>

<div id="EditInterview" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width:950px;margin:0 0 0 -500px;">
    <div class="modal-header">
        <!-- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button><br> -->
        <h3 id="myModalLabel">Add new interview</h3>
    </div>
    <div class="modal-body">
        <div id="addinterviewForm">
            <p class="lead"><span class="label label-info">Anons title</span></p>
            <?php

            $interview_id = array(
                'interview_id' => $interview->getId());

            echo form_open_multipart('/InterviewController/saveInterview', '', $interview_id);

            $anonstitle_date = array(
                'name'        => 'anonstitle',
                'id'          => 'anonstitle',
                'maxlength'   => '1000',
                'value'       => $interview->getAnonstitle(),
                'rows'        => '5',
                'cols'        => '122'
            );?>
            <span class="label label-info"> <?php echo form_textarea($anonstitle_date);?> </span>

            <br><br><p class="lead"><span class="label label-info">Anons</span></p>
            <?php

            $anons_data = array(
                'name'        => 'anons',
                'id'          => 'anons_area',
                'value'       => $interview->getAnons()
            );?>
            <span class="label label-info"> <?php echo form_textarea($anons_data); ?> </span>

            <br><br><p class="lead"><span class="label label-info">Anons image</span></p>
            <span class="label label-info"> <?php echo form_upload('anonsphoto'); ?></span> <br /><br />

            <p class="lead"><span class="label label-inverse">Interview title</span></p>
            <?php

            $interviewtitle_date = array(
                'name'        => 'interviewtitle',
                'id'          => 'interviewtitle',
                'maxlength'   => '1000',
                'value'       => $interview->getInterviewtitle(),
                'rows'        => '5',
                'cols'       => '122'
            );?>
            <span class="label label-inverse"> <?php echo form_textarea($interviewtitle_date);?> </span>

            <p class="lead"><span class="label label-inverse">Interview</span></p>
            <?php
            $interview_data = array(
                'name'        => 'interview',
                'id'          => 'interview_area',
                'value'       => $interview->getInterview()
            );?>
            <span class="label label-inverse"> <?php echo form_textarea($interview_data); ?></span>

            <br><br><p class="lead"><span class="label label-inverse">Interview image</span></p>
            <span class="label label-inverse"><?php echo form_upload('interviewphoto'); ?> </span> <br /><br />
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Cancel</button>
        <button class="btn btn-primary" type="submit">Save</button>
    </div>
    <?php form_close();?>
</div>

<script type="text/javascript">
    CKEDITOR.replace( 'anons_area', { width: '900px', height: '200px' } );
    CKEDITOR.replace( 'interview_area', { width: '900px', height: '200px' } );
</script>

<div class="span2" align="left">
<?php
echo form_open('/InterviewController/deleteInterview/' . $interview->getId());?>
<button class="btn btn-primary btn-large" type="submit">Delete</button>
<?php form_close();?>
</div>


<div class="span9">
    <div align="center"><h3><?=$interview->getInterviewtitle()?></h3></div>
    <img src='<?=$interview->getInterviewphoto()?>' align = "left" hspace ="20" vspace="20">
    <p><?=$interview->getInterview()?></p>
</div>
4

2 回答 2

0

你应该能够做这样的事情:

<?php echo form_open($this->uri->uri_string(),$form1); 
              echo form_textarea($comment);
              echo form_submit('submit','submit');
              echo form_close();
?>
<?php echo form_open($this->uri->uri_string()); 
              echo form_dropdown('portion', $portion_options); 
              echo form_submit('book','book');
              echo form_close();
?>

你的控制器看起来像这样:

if($this->input->post()){
  switch($this->input->post('form_id')){
  case 1:
    // do stuff
  break;
  case 2:
    // do stuff
  break;
  }
}
于 2013-03-22T19:49:04.237 回答
0

简要查看您的代码,您的 form_close() 函数调用似乎没有正确嵌套在 HTML 中。

尝试将您的 form_open() 语句放在第一个表单 ( /InterviewController/saveInterview) 中,就在开始 div 的下方<div id="EditInterview" class="modal hide fade"...

希望这可以帮助...

于 2013-03-26T15:18:52.133 回答