I have a dialog form.
<div id="dialog-form" title="Create new Admin">
<p class="validateTips">All form fields are required.</p>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="" class="text ui-widget-content ui-corner-all" />
<label for="role">Role</label>
<select name="user_role" class="select ui-widget-content ui-corner-all" >
<option value="administrator">Administrator</option>
<option value="visitor">Visitor</option>
<option value="Helper">Helper</option>
</select>
<label for="email">Email</label>
<input type="text" name="login_email_admin" id="login_email_admin" value="" class="text ui-widget-content ui-corner-all" />
<label for="Passoword">Password</label>
<input type="passowrd" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
<label for="Passoword">Re-Enter Password</label>
<input type="password" name="password_2" id="password_2" value="" class="text ui-widget-content ui-corner-all" />
<input style="margin-top:15px;" type="submit" name="add_admin" value="Add New Admin">
</fieldset>
</form>
i am using following php code in views to take data from this dialog form when it will be submitted..
<?php
if($_POST['add_admin'])
{
$this->user_role=$this->input->post('name');
$this->user_role=$this->input->post('user_role');
$this->login_email_admin=$this->input->post('login_email_admin');
$this->password=$this->input->post('password');
$this->load->database();
$this->db->insert('admin_user',$this);
}
?>
But it’s not inserting into the db.this problem really stuck me.i am calling page itself when form submit, i dont know what is the reason its not working.
additionally is there a way that i will get rid of using models, instead i can do all db operations in views?
This code is wrong in many aspects:
$thisreference, which contains way much more than those propertiesShould be something like:
See insert chapter on manual for reference.
Also, I don’t know why you want to do that inside a view, you should do the insert in a model, and the checking for the form being submitted must be done in the controller (ideally you could use the Form Validation class, which is very handy for this task.
You’re using a framework with an MVC architecture but in this piece of code you’re taking advantage of almost nothing from both…