CodeIgniter表单助手 - 点击提交时没有任何反应

时间:2015-07-23 09:16:30

标签: php forms twitter-bootstrap codeigniter action

我想将Bootstrap表单与CodeIgniter集成,我遵循文档(https://www.codeigniter.com/user_guide/helpers/form_helper.html),但是当我点击提交表单时没有任何反应。你能告诉我我做错了吗?

这是我的代码:

<?php
 $form = array(
'name' => "SentMessage",
'id' => "contactForm"
 );
 $email = array(
'name' => 'email',
'class' => "form-control",
'placeholder'=>"Email",
'id' => "email",
'required data-validation-required-message'=>"Please, enter your email."
 );
 $password = array(
'name' => 'password',
'class' => "form-control",
'placeholder' => "Password",
'id' => "password",
'required data-validation-required-message'=>"Please, enter your password."
 );
 $cpassword = array(
'class' => "form-control",
'placeholder' => "Confirm password",
'id' => "cpassword",
'required data-validation-required-message' => "Please, confirm your         password"
 );
 $submit = array(
'name' => 'signup_submit',
'value' => 'Submit',
'class' => 'btn btn-default'
 );

 ?>

<?php echo form_open('login_register/signup_validation', $form)?>
<div class="row control-group">
    <div class="form-group col-xs-12 floating-label-form-group controls">
        <label>Email</label>
        <?php echo form_input($email); ?>
        <p class="help-block text-danger"></p>
    </div>
</div>
<div class="row control-group">
    <div class="form-group col-xs-12 floating-label-form-group controls">
        <label>Password</label>
        <?php echo form_password($password); ?>
        <p class="help-block text-danger"></p>
    </div>
</div>
<div class="row control-group">
    <div class="form-group col-xs-12 floating-label-form-group controls">
        <label>Confirm Password</label>
        <?php echo form_password($cpassword); ?>
        <p class="help-block text-danger"></p>
    </div>
</div>
<br>
<div id="success"></div>
<div class="row">
    <div class="form-group col-xs-12">
        <?php echo form_submit($submit);?>
    </div>
</div>
<?php form_close();?>

2 个答案:

答案 0 :(得分:0)

您的代码看起来很好。 检查,如果您有初始化帮助程序,如URL和FORM 。此外,请确保控制器中存在login_register / signup_validation 方法。

答案 1 :(得分:0)

我按原样使用了您的代码,将其放在我知道正在工作的CI / Bootstrap环境中的CI视图中,并且它运行良好。我添加的唯一内容是在页面顶部加载表单助手,然后输入print_r语句进行调试。我还将您的提交URL更改为指向自身,以便我可以看到提交是否有效,并且确实如此。你可以在http://home.toolzilla.net/test

看到它

我没有看到Bootstrap如何影响这一点,但测试站点是一个完全正常工作的Codeigniter / Bootstrap环境,你可以在这里看到设置https://bitbucket.org/greco-roamin/toolzilla

以下是测试页面中的确切代码,除了我上面提到的更改外,它与您的完全相同。

<?php
$this->load->helper('form');
print_r($this->input->post());

 $form = array(
'name' => "SentMessage",
'id' => "contactForm"
 );
 $email = array(
'name' => 'email',
'class' => "form-control",
'placeholder'=>"Email",
'id' => "email",
'required data-validation-required-message'=>"Please, enter your email."
 );
 $password = array(
'name' => 'password',
'class' => "form-control",
'placeholder' => "Password",
'id' => "password",
'required data-validation-required-message'=>"Please, enter your password."
 );
 $cpassword = array(
'class' => "form-control",
'placeholder' => "Confirm password",
'id' => "cpassword",
'required data-validation-required-message' => "Please, confirm your         password"
 );
 $submit = array(
'name' => 'signup_submit',
'value' => 'Submit',
'class' => 'btn btn-default'
 );

 ?>

<?php echo form_open('test', $form)?>
<div class="row control-group">
    <div class="form-group col-xs-12 floating-label-form-group controls">
        <label>Email</label>
        <?php echo form_input($email); ?>
        <p class="help-block text-danger"></p>
    </div>
</div>
<div class="row control-group">
    <div class="form-group col-xs-12 floating-label-form-group controls">
        <label>Password</label>
        <?php echo form_password($password); ?>
        <p class="help-block text-danger"></p>
    </div>
</div>
<div class="row control-group">
    <div class="form-group col-xs-12 floating-label-form-group controls">
        <label>Confirm Password</label>
        <?php echo form_password($cpassword); ?>
        <p class="help-block text-danger"></p>
    </div>
</div>
<br>
<div id="success"></div>
<div class="row">
    <div class="form-group col-xs-12">
        <?php echo form_submit($submit);?>
    </div>
</div>
<?php form_close();?>