The Form tutorial - the beginning

Ok, in my previous post I detailed on what this tutorial should cover. Now it’s time for the actual tutorial. Before I illustrate the usage of several approaches towards forms we have to deal with some common things. The form we’re going to create deals with food preferences so we’ll call the database table we’re going to use ‘preferences’.

Table definition, add to your db

CREATE TABLE IF NOT EXISTS `preferences` (
  `id` smallint(6) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) collate utf8_unicode_ci NOT NULL,
  `email` varchar(255) collate utf8_unicode_ci NOT NULL,
  `preference` varchar(255) collate utf8_unicode_ci NOT NULL,
  `comment` tinytext collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

Every table needs a model and since we’re using ORM, the model will utilize ORM.
models/preference.php

class Preference_Model extends ORM {}

It’s as simple as models can get. I might add to it later on for the Formation module.

Now we need a controller with two methods, one for adding records, one for editing.
controllers/preferences.php

class Preferences_Controller extends Controller{
public function insert() {}
public function update($id){}
}

This is what all approaches to forms have in common.

I will deal with the update($id) in later posts. I’ve dedicated category to all posts concerning themselves with this tutorial.

The tutorials:

  1. Normal validation
  2. Formation
  3. Forge


5 Responses to “The Form tutorial - the beginning”

  1. Peter Briers Says:

    The links don’t work anymore.

  2. dlib Says:

    It’s on my todo list. You can replace the hostname with learn.kohanaphp.com and you’ll get to the right url though.

  3. Learning Kohana » The Form tutorial - Formation Says:

    [...] you’ve set up and the model as seen in a previous post we can now begin with building a form using [...]

  4. Heptat Says:

    No offense, but “it’s on my todo list”?? How hard is it to update a link…and that was in May. That’s a long todo list.

    I’m new to kohana, and while I’m finding it interesting to work with, I suspect the lack of good documentation must be turning potential users away.

  5. dlib Says:

    I’m sorry,I’m terribly busy with a lot of stuff and Kohana has been off the radar for a while. If you change the domain of the links to the current domain ‘learn.kohanaphp.com’ it should work.

Leave a Comment