无法在一个文档中放置2个form_open

时间:2013-03-22 19:41:37

标签: html forms view codeigniter-2

我正在一个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>

2 个答案:

答案 0 :(得分: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;
  }
}

答案 1 :(得分:0)

简要地查看代码,看起来好像你的form_close()函数调用没有正确嵌套在HTML中。

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

希望这会有所帮助......