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');
}
}
}
?>
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 the
form_open()
function: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:
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
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.
Answer
Solution:
Load form helper,
And use,
Instead of,
Answer
Solution:
First in your Controller put in:
And Change
</form>
to :