Welcome Guest, Not a member yet? Register   Sign In
Update DB from HTML form
#1

[eluser]Unknown[/eluser]
Hi all,

I currently have a web form looking like this;

Code:
<form>
  Username: &lt;input type="text" disabled="disabled" value="' . $data['username'] . '"/&gt; </br>
  First Name: &lt;input type="text" value="' . $data['firstName'] . '"/&gt; </br>
  Last Name: &lt;input type="text" value="' . $data['lastName'] . '"/&gt; </br>
  Email Address: &lt;input type="text" value="' . $data['email'] . '"/&gt; </br>
  Enabled: &lt;input type="checkbox" value="' . $data['enabled'] . '"/&gt; </br>
  Admin: &lt;input type="checkbox" value="' . $data['admin'] . '"/&gt; </br>
        
&lt;/form&gt;

I would now like to add a submit button to this and allow users to update their details as they see fit.

Is there any documentation on how this should be achieved? I'm aware of how to do it the old PHP\MySQL way, but not through CI!

Any guidance would be appreciated.

Thanks Smile
#2

[eluser]boltsabre[/eluser]
I suggest you have a look at some of the online video tutorials, and code along with them (but watch out, most are for CI 1.7, not CI 2+, which have some differences, namely the name of the contoller (CI_Controller in V2+, not simply Controller in <2, how to construct your constructor, etc, but once you get them sorted out the vast bulk of the tutorials are valid). Also make sure you code along with them, much better than just watching a 45 minute tutorial.

This will give you an idea of how MVC works, but basically in a nut shell your html/view form posts to your controller (that would be your from action which you have omitted in your code above), your controller then runs form validation, and if it passes it passes the post data to the model which then runs some kind of DB action (insert/update/delete/view).

Also have a look at the user documentation, it's pretty awesome! For example, there is a CI function for creating your opening form tag. This will automatically add your hidden CSFR input if you have it activated.

So yeah, go through the documentation and go through some online video tut's and you'll have a much better understanding of what CI is, and how you work with it.

Good luck!




Theme © iAndrew 2016 - Forum software by © MyBB