php - Form is not getting displayed in codeigniter.

468

I am new to code igniter. I've created a form but it is not display properly.

When I put

<?php echo form_open('sms'); ?> instead of<form action="">tag here in my form and controller, I can't understand why it is not displayed.

<?php echo form_open('sms'); ?>
      <p>
       <label><strong>Username</strong>
<input type="text" name="textfield" id="textfield" />
       </label>
     </p>
      <p>
       <label><strong>Password</strong>
 <input type="password" name="textfield2" id="textfield2" />
      </label>
      </p>

      <input type="submit" value="Authentification" name="auth" />
       <label>
       <input type="checkbox" name="checkbox" id="checkbox" />
       Remember me</label>      
     </form>

and my controller is

<?php

class  sms extends CI_Controller{
function school(){
    $this->load->view('school/index.php');

    if($this->input->post('auth',TRUE)){
     $this->load->view('school/dashboard.php');
    }
    else{
    $this->load->view('school/index.php');

    }
}

}

?>

852

Answer

Solution:

If this is your entire script for the most part, it looks like you need to load the helper first from the CodeIgniter Form Helper Page.

If you don't have this line, try adding it before theform_open() function:

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

While I have used CodeIgniter, it's been a while. Let me know if that changes the result.

Edit: Since you've chosen my answer I'll include this one, credits go out to devo:

You could change</form> to:<?php echo form_close(); ?>. There are pros and cons for this method though, and without using arguments you might be better off sticking with</form>.

I'll explain further:

<div >
  <div >
    <?php $this->load->helper( 'form' ); ?>
    <?php $end = '</div></div>'; ?>
    <?php echo form_open( 'register' ); ?>

    <!-- Form Inputs Here -->

    <?php echo form_close( $end ); ?>

    <!-- Echos '</form></div></div>' -->

So for closing the form without arguments, the</form> tag works best, both by performance and simplicity. The example used above is a rather simplistic view of what you can do with it, since what I wrote is not very efficient either.

However, this is still php we're talking about, so perhaps the craftier among us could put it to better use.

End Edit

327

Answer

Solution:

Have you loaded the form helper? You can use $this->load->helper('form'); in your controller action, her inside function school(). You can then use form helper in the view pages.

214

Answer

Solution:

Load form helper,

$this->load->helper('form');

And use,

echo form_close()

Instead of,

</form>
290

Answer

Solution:

First in your Controller put in:

$this->load->helper('form');

And Change</form> to :

<?php echo form_close(); ?>

People are also looking for solutions to the problem: php - MySQL search case insensitive

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.