简体   繁体   中英

CodeIgniter form helper - nothing happens when clicking on submit

I want to integrate Bootstrap form with CodeIgniter and I followed the documentation ( https://www.codeigniter.com/user_guide/helpers/form_helper.html ), but when I click to submit the form nothing happens. Can you tell me where I do it wrong?

Here is my code:

<?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();?>

Your code looks fine. check if you have initialize helper like URL and FORM or not. Also, make sure login_register/ signup_validation method is present in controller.

I took your code as-is, put it in a CI view that is in a CI/Bootstrap environment that I know is working, and it worked perfectly. The only thing I added was loading the form helper at the top of the page and I put in a print_r statement for debugging. I also changed your submit URL to point back to itself so I could see if the submit worked, and it did. You can see it here http://home.toolzilla.net/test

I don't see how Bootstrap could affect this, but the test site is a fully working Codeigniter/Bootstrap environment and you can see the set-up here https://bitbucket.org/greco-roamin/toolzilla

Here is the exact code in the test page, which is identical to yours except the changes I mentioned above.

<?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();?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM