Easy Form Generation Using FuelPHP

Easy Form Generation Using FuelPHP

Tutorial Details
  • Program: Fuel PHP Framework
  • Version (if applicable): 1.1
  • Difficulty: Easy
  • Estimated Completion Time: 1 hr

Thanks to FuelPHP’s fieldset class, working with forms couldn’t be easier. With a few lines of code, you can easily generate and validate a form. Today, we’re going to learn how to do just that!


The Fieldset class is used to create a form and handle its validation in an object-oriented way. It uses the Form and Validation classes. This class, itself, is only meant to model the fieldset and its fields, while the other two classes perform the brunt of the work.


Setup Fuel

We need a FuelPHP installation with an RM package enabled. I’m going to use a MySQL database with a sample table. While the Fieldset class can be configured to use a normal model, using an ORM will save us some time.

If you haven’t reviewed the first couple parts of the FuelPHP series here on Nettuts+, now is a great time to check out part one and two, by Phil Sturgeon.

Set up a database connection at fuel/app/config/development/db.php.

		return array(
		  'default' => array(
		 	 'connection'  => array(
		 		 'dsn'  	=> 'mysql:host=localhost;dbname=blog',
		 		 'username' => 'root',
		 		 'password' => 'root',
		 	 ),
		  ),
		);
		

Enable the ORM package through fuel/app/config.php

			'packages'  => array(
				'orm',
			),
		

And, finally, here’s the SQL for the table I’m using for this tutorial.

			CREATE TABLE  `blog`.`posts` (
			`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
			`post_title` VARCHAR( 100 ) NOT NULL ,
			`post_content` TEXT NOT NULL ,
			`author_name` VARCHAR( 65 ) NOT NULL ,
			`author_email` VARCHAR( 80 ) NOT NULL ,
			`author_website` VARCHAR( 60 ) NULL,
			`post_status` TINYINT NULL
			) ENGINE = INNODB;
		

Model

We need a model for our controller to interact with the posts table. Go ahead and create a post.php inside app/classes/model/. Create a Model_Post class and make sure it extends \Orm\Model. The ORM will automatically use the posts table in our database since we have used the singular of “posts”. If you want to set a different table, set up a static property called $_table_name.

		class Model_Post extends \Orm\Model
		{
			protected static $_table_name = 'posts'; //set the table name manually
		}
	

Setting Up the Properties

We should specify the columns of our posts table within our model. At the same time, we can also set up labels, form validation rules to use with our fieldset class to generate the form. All of these go in an associated array, called $_properies. With everything in place, our final model should look like so:

	class Model_Post extends \Orm\Model
	{
		protected static $_table_name = 'posts';

		protected static $_properties = array(
			'id', 
			'post_title' => array( //column name
				'data_type' => 'string',
				'label' => 'Post Title', //label for the input field
				'validation' => array('required', 'max_length'=>array(100), 'min_length'=>array(10)) //validation rules
			),
			'post_content' => array( 
				'data_type' => 'string',
				'label' => 'Post Content',
				'validation' => array('required')
			),
			'author_name' => array( 
				'data_type' => 'string',
				'label' => 'Author Name',
				'validation' =>  array('required', 'max_length'=>array(65), 'min_length'=>array(2))
			),
			'author_email' => array( 
				'data_type' => 'string',
				'label' => 'Author Email',
				'validation' =>  array('required', 'valid_email')
			),
			'author_website' => array( 
				'data_type' => 'string',
				'label' => 'Author Website',
				'validation' =>  array('required', 'valid_url', 'max_length'=>array(60))
			),
			'post_status' => array(
				'data_type' => 'string',
				'label' => 'Post Status',
				'validation' => array('required'),
				'form' => array('type' => 'select', 'options' => array(1=>'Published', 2=>'Draft')),
			)
		);
	}
	

Let’s examine what options we can use. data_type simply holds the fields’s type. It could be either string, integer or mysql_date. The value for the label property will be shown as the field label once the form is generated. validation accepts an array of validation rules. By default, these fields will be text input fields. Using the form, you can make it a select or texarea.

The ORM treats the column named id as the primary and will not be shown when generating a form. If your table’s primary key column is different, use the $_primary_key property to specify it.

	/**
	 * Post Model
	 */
	class Model_Post extends \Orm\Model
	{
		protected static $_table_name = 'posts';

		protected static $_primary_key = array('id'); //you can set up multiple columns, .. $_primary_key => array('id', 'user_id')
	}
	

Controller

Now that the model is ready, let’s create the controller. Controllers should be placed within fuel/app/classes/controller/. I’ve created a controller, called Controller_Posts (posts.php) and extended it from Controller_Template.

		/**
		 * Post Controller fuel/app/classes/controller/posts.php
		 */
		class Controller_Posts extends \Controller_Template
		{
			//list posts
			function action_index()
			{

			}

			//add new one
			function action_add()
			{

			}

			//edit
			function action_edit($id)
			{

			}
		}
	

Users will be able to see a list of posts, add new ones, or edit an existing one. Because I’m using the template controller, I can use a base template file to work with. Templates go in fuel/app/views/template.php

	<!DOCTYPE html>
	<html>
	<head>
	    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	    <?php echo Asset::css('bootstrap.css'); ?>
	</head>

	<body>

		<div id="content">

			<p>
				<?php
					echo \Html::anchor('posts/index', 'Listing'), '&nbsp;', \Html::anchor('posts/add', 'Add');
				?>
			</p>

			<?php if(isset($messages) and count($messages)>0): ?>
			<div class="message">
				<ul>
				<?php
					foreach($messages as $message)
					{
						echo '<li>', $message,'</li>';
					}
				?>
				</ul>
			</div>
			<?php endif; ?>

			<?php echo $content; ?>
		</div>

	</body>
	</html>
	

This is merely standard HTML markup with the Twitter bootstrap. The $content variable will have the content. We can set an array of messages and if we do, it will be printed as an unordered list.


Adding New Posts

This is where the fun begins. We’re going to generate the form for adding new posts. As you might have guessed, we’ll be working with the action_add() method. Let’s generate the form and pass it to our template.

	//add new one
	function action_add()
	{
		$fieldset = Fieldset::forge()->add_model('Model_Post');
		$form     = $fieldset->form();

		$this->template->set('content', $form->build(), false); //false will tell fuel not to convert the html tags to safe string.
	}
	

Fieldset::forge() will return a new instance of the fieldset class. It’s the same as doing new Fieldset. However, using the forge method here, we can name our instances. If we call an instance twice with the same name, an existing instance will be returned if available [the Factory pattern]. To name your instance, pass the name to the forge method. Fieldset::forge('new_post')

Using the add_model method, we pass the model which we want the forms to be generated from. Fieldset will grab the data from $_properties to generate the form. Calling the form() method from the fieldset object will return an instance from Form class, and by calling the build() method, we can get a html (string) output of the form.

		$this->template->set('content', $form, false);
	

Finally, we pass the $form to the template as content. Another method of passing variables to a template is $this->template->content = $form.

Fire up your browser and navigate to http://path_to_site/index.php/posts/add. You should see a form identical to this.

No submit button? Let’s fix that. We need to add a new field to our form object.

		$form->add('submit', '', array('type' => 'submit', 'value' => 'Add', 'class' => 'btn medium primary')); 
	

Using the add method we can add additional fields to our form. First parameter is our new fields name, second is for label, for the third parameter we pass an array of attributes.

After adding this, our action_add() will look like this.

	function action_add()
	{
		$fieldset = Fieldset::forge()->add_model('Model_Post');
		$form     = $fieldset->form();
		$form->add('submit', '', array('type' => 'submit', 'value' => 'Add', 'class' => 'btn medium primary'));

		$this->template->set('content', $form->build(), false); 
	}
	

And our form..


Validation and Saving

Now that we have a nice form, let’s validate it and save to the database. The fieldset object includes an instance from FuelPHP’s validation class. All the rules has been applied and ready to go.

	function action_add()
	{
		$fieldset = Fieldset::forge()->add_model('Model_Post');
		$form     = $fieldset->form();
		$form->add('submit', '', array('type' => 'submit', 'value' => 'Add', 'class' => 'btn medium primary'));

		if($fieldset->validation()->run() == true)
		{
			$fields = $fieldset->validated();

			$post = new Model_Post;
			$post->post_title     = $fields['post_title'];
			$post->post_content   = $fields['post_content'];
			$post->author_name    = $fields['author_name'];
			$post->author_email   = $fields['author_email'];
			$post->author_website = $fields['author_website'];
			$post->post_status    = $fields['post_status'];

			if($post->save())
			{
				\Response::redirect('posts/edit/'.$post->id);
			}
		}
		else
		{
			$this->template->messages = $fieldset->validation()->errors();
		}

		$this->template->set('content', $form->build(), false); 
	}
	

$fieldset->validation() returns a validation class instance and by accessing its run() method we can check if validation is passed. If so, we add a new post to our database. $fieldset->validated() will return an array of validated fields. If validation is passed and post is saved, the user will be redirected to the edit page, otherwise pass the validation errors to our template as message variable.

If you try to submit some invalid data, you will get an output like so:

Everything seems fine except for one issue: data we submit doesn’t appear after the page refresh. Not to worry, one method call and you’re done.

	$fieldset = Fieldset::forge()->add_model('Model_Post')->repopulate(); //repopulate method will populate your form with posted data
	

Cool, huh? Add some valid data and it will redirect to the action_edit() method, which is not ready yet.


Editing a Post

Editing a section is pretty much the same as our add post section. Except we need to populate the data with an existing post. I’m going to duplicate the action_add code.


	function action_edit($id)
	{
		$post = \Model_Post::find($id);

		$fieldset = Fieldset::forge()->add_model('Model_Post')->populate($post); //model post object is passed to the populate method
		$form     = $fieldset->form();
		$form->add('submit', '', array('type' => 'submit', 'value' => 'Save', 'class' => 'btn medium primary'));

		if($fieldset->validation()->run() == true)
		{
			$fields = $fieldset->validated();

			//$post = new Model_Post;
			$post->post_title     = $fields['post_title'];
			$post->post_content   = $fields['post_content'];
			$post->author_name    = $fields['author_name'];
			$post->author_email   = $fields['author_email'];
			$post->author_website = $fields['author_website'];
			$post->post_status    = $fields['post_status'];

			if($post->save())
			{
				\Response::redirect('posts/edit/'.$id);
			}
		}
		else
		{
			$this->template->messages = $fieldset->validation()->errors();
		}

		$this->template->set('content', $form->build(), false); 
	}
	

With some small modifications to our action_add() method, we have our edit method. repopulate() method has been replaced by populate() method. Using the populate method, we can populate a form with an existing post’s data.

In this case, we grab the post from our database using the $id parameter, then pass it to the requisite method. We don’t need $post = new Model_Post; anymore because we are not adding any thing to the database. The $post object we create in the beginning is used to assign the new values. Once edited it will redirect back to its edit screen. We’re done! Add some posts, and try editing them.


Listing Pages

Let’s build up the listing section so users can see all the posts in one place.

The listing is handled by the action_index() method

	//list posts
	function action_index()
	{
		$posts = \Model_Post::find('all');

		$view  = \View::forge('listing');
		$view->set('posts', $posts, false);

		$this->template->content = $view; //In config file View objects are whitelisted so Fuelphp will not escape the html.
	}
	

Model_Post::find('all') will return an array of posts objects for all of our posts. Using View::forge(), a new view object is instantiated. The parameter for View::forge() is the name for our specific view. It’s located at app/views/listing.php. The array of posts object ($posts) is then passed to our view. The Listing view will take care of the listing and finally we assign the view to $this->template->content.

In the view, we loop through $posts and generate the list.

	<?php
	/**
	 * Listing view, views/listing.php
	 */
	if($posts):
		foreach($posts as $post):
	?>

	<div class="post">
		<h2><?php echo $post->post_title; ?> <small><?php echo \Html::anchor('posts/edit/'.$post->id, '[Edit]');?></small></h2>
		<p><?php echo $post->post_content; ?></p>
		<p>
			<small>By <?php echo $post->author_name; ?></small><br />
			<small><?php echo $post->author_email; ?></small><br />
			<small><?php echo $post->author_website; ?></small><br />
		</p>
	</div>

	<?php 
		endforeach;
	endif;
	?>
	

If you have any posts in the database, it will look something like this.


Some Final Modifications

Everything seems to be working correctly; however, there are some minor issues. The generated form has a text field for the post content, which would be better off as a textarea.

	//Model_Post
	'post_content' => array( 
		'data_type' => 'string',
		'label' => 'Post Content',
		'validation' => array('required'),
		'form' => array('type' => 'textarea') //will give us a textarea
	),
	

You can pass all the field types text, textarea, select, radio etc. For select or radio elements, you can set the options. Setting options for a select using another table is also possible. If you want to change the default layout, place a form config file in fuel/app/config/form.php If you’re not sure about what to put in there, copy stuff from fuel/core/config/form.php. Fuel uses this file to generate the forms.


Summary

I hope you now have a clear understanding of the fieldset class. If you have any questions, please let me know in the comments below. Thank you so much for reading!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.weztec.com Phil

    Hi,

    Thanks for taking the time to produce this tutorial and to help promote FuelPHP.

    My only comment would be that examples always seem to be built using the orm and leads people to think that to use FuelPHP you must use the orm which is simply not true.

    A tutorial using DB class and the extremely useful Model_Crud class would be a much better way of really showing off the power of FuelPHP.

    The Fieldset class works just as well using these.

    Just my 2c worth.

    Phil

  • http://daveismyname.com Dave

    is this line right?

    echo \Html::anchor(‘posts/index’, ‘Listing’), ‘ ’, \Html::anchor(‘posts/add’, ‘Add’);

    the \ before Html looks strange if its meant to be there.

    • Sahan
      Author

      It’s actually referencing the global namespace. However in here it’s not required. For instance FuelPHP has modules and if you were having this code in a module you would need to add the \ to use Core classes, otherwise it’s referencing Module_Name_Space\Html. http://docs.fuelphp.com/general/modules.html

  • Sam

    FuelPHP is great. It’s community is still very small and activity is declining. I encourage everyone to try and contribute whatever possible to this awesome framework! it’s easy to learn, well documented and packed with almost everything you need to get an awesome web app running in no time!

    Thanks for posting, good read

    • Daniel Petrie

      What makes you think the activity is declining? If anything, I’ve only seen growth

  • wes

    Not bad.

  • http://blog.01tchat.com Pierre

    Good Framework!
    Thanks

  • http://www.veb4design.com Nima

    I’d rather use YII .. but still a good post though.
    Nima

  • Felipe

    I see a lot of duplicated and hard-to-maintain code. IMHO, it may influence beginners in a bad way. Sorry for the awful english.

    • Sahan
      Author

      I agree. add and edit methods can be simplified. You could even roll a function in a base model to get a fieldset object for a model. I wanted to concentrate on Fieldset’s functionality. Thanks for the comment.

  • Rogers Vizcaino

    Great, but what if I want to use some checkbox, radio or select?

    • Sahan
      Author

      You can use ‘form’ => array(‘type’ => ‘radio’) or ‘form’ => array(‘type’ => ‘checkbox’)

  • Dave

    Thanks. This is useful to know.

  • http://silentworks.co.uk Andrew

    I think you are missing a conditional statement to know wether a POST has been sent or not? Currently this if($fieldset->validation()->run() == true) will return false if validation is not run, so will fall to the else statement which will try and get errors.

    Since this is empty it might not be a problem but I would think for best practice, especially for beginners you might want to add in a POST check.

    Nice tutorial otherwise.

    • Sahan
      Author

      $fieldset->validation()->run() will actually check for this. It will only set errors if Input::method() == ‘POST’. But yeah you can add the condition which will stop from calling the run method if there’s no POSTs made.
      Thanks for reading!

  • http://maomuffy.blogspot.com Mfawa Alfred Onen

    FuelPHP, the next upgrade from Codeigniter…Nice!

  • http://blaxus.net/ David D’hont

    Nice article. I just think stuff like this is a bit Overkill.

    It takes me 30 minutes to create a CRUD for my own custom system like here. Validation included.
    And If I use Server Side Validation classes it could be as easy as 15 minutes. And I save so much code.

  • http://www.github.com/dotink/inkwell Matthew J. Sahagian

    Does anyone know off hand if Fuel will automatically act/react with regards to validation on the model that doesn’t fit with the database schema? i.e. Does it properly determine violations of the schema as validation errors or does it just throw the SQL exception upstream?

    One of the things I’m able to do with Flourish’s ORM is add as many standard constraints and restrictions on the database schema, and use that as the most basic validation “automatically” with the ORM layer. This to me is preferable over having to define these limitations in the schema, and then additionally having to provides the same core restrictions in the model.

    Database schema lets us know:

    1) What cannot be NULL (i.e. required)
    2) The maximum length of string fields
    3) Default values

    In the better developed databases it also can let us know the following:

    1) Whether or not there are default options based on a check constraint
    2) Whether or not the value has to inevitably match some other record’s value via foreign constraints

    inKWell used this pretty extensively in the alpha versions of the admin panel extension, particularly for generating the default views for working with records — what non-on-the-fly scaffolders tend to do now.

    Additional information was added in the model config, of course, but it was only that which wasn’t available in the schema, or only required to be that. For example, if you assigned a column to a password column, it would automatically handle the hashing + identifying it as a password in the admin panel as opposed to standard text input.

    Combine that with what inevitably would have been the HTML five version, and I could imagine very robust data types at the model level, while maintaining the fundamental data integrity at the schema level in the event that there are multiple applications hitting the same database.

  • http://zackperdue.com Zack

    Why not just use Kohana? Thats what FuelPhp basically is anyways.

    • ME

      what’s Kohana?

      • http://consil.co.uk/ Jason

        Another framework of no relevance to what is being discussed here.

    • http://roadha.us haliphax

      Do you post, “Why not just use FuelPHP” on Kohana posts, as well?

    • http://philsturgeon.co.uk Phil Sturgeon

      Did that make you feel clever? Because it doesn’t make you look it. We’ve been through the fact that we share the CSRF 100 times in countless different forums.

      Anyone who knows a damn thing about FuelPHP will instantly start seeing the difference, but anyone who looks at it for 5 minutes will probably jump to the same absolutely wrong conclusion as you.

      • Rob

        Phil, its comments like these that make me dislike you. You may be an experienced programmer, but you really have a bad attitude. My perception of the way you interact with others makes me not want to use Fuel or Pancake or anything with your name on it. I’ve used Fuel, and it’s good, but I just can’t get past the fact that it has your name on it. I loathe the fact that you are one of the core CodeIgniter contributors.

      • http://www.jeffrey-way.com Jeffrey Way

        Yikes – that’s a bit harsh, Rob. I didn’t see anything in Phil’s comment that warranted that sort of response.

      • http://www.github.com/dotink/inkwell Matthew J. Sahagian

        Am I the only one missing where someone said anything regarding CSRF before Phil?

      • Andrew Shooner

        I’m just getting familiar with Fuel (codebase, community, etc) and I’ve run across ~3 posts from Phil, all of which were very condescending and unproductive. The framework looks awesome, but I’d have to say this attitude does a real disservice to building the community. I would not want to be speaking up for the same project as comments like this.

  • begs

    Thanks for another great FuelPHP Tutorial.
    I’m using it instead of Codeigniter and Kohana. It has really great features and is easy to setup.

    • http://www.pixlatedstudios.com Aayush Ranaut

      So i wanted to use codeignitor…so should i skip learning it and learn fuelphp instead…….

      • begs

        I think that you could start learning Codeigniter because there are many many tutorials out there for it. Also on Nettuts there is a series from Jeffrey.
        After learning Codeigniter you can switch to FuelPHP easily, because FeulPHP is a fork of Codeigniter and feels much the same.

      • Daniel Petrie

        As stated several time before, FuelPHP is not a fork of CodeIgniter, nor Kohana.. but somehow people think its a fork of both. It was built from the ground up using PHP 5.3. It does borrow concepts from both frameworks along with some from others.

  • Sergey

    Great intro tut, thanks!
    One question regarding framework’s models, is it really necessary to specify data_type per each field? If it’s something that can be retrieved automatically, then why should it be hard-coded?

    • http://fuelphp.com Jelmer Schreuder

      Actually the data_type setting isn’t required here. It’s only necessary for the Typing observer and would need ‘varchar’ instead of ‘string’. These types can also be fetched automatically but that requires an extra query on each and every request and doesn’t allow you to add these form & validation keys. Also data_type along with the Typing observer allows for some specialized types like ‘serialized’ and ‘json’ to be used.

  • Ahmad

    I think use pattern like activerecored give better results in term of productivity , see how yii framework Activerecord .

  • http://www.maiconweb.com Maicon Sobczak

    Seems to me too much code for a simple form.

    • http://roadha.us haliphax

      As with most examples, it is not as complex as the situations you will encounter out in the real world. It would take too much time and effort to build such a situation, then explain its idiosyncrasies, then show how the code will take care of it. Just imagine this form is 10x bigger, involves eCommerce, and has some field definitions that are being altered dynamically. ;)

    • http://philsturgeon.co.uk Phil Sturgeon

      This is a simple form used as an example for how to handle much more complicated examples. If an extremely convoluted form was used in a “how to” example then it would hide what is happening.

      Simple forms can just use Form::open() or you want to go retro you can use HTML and $_POST, but if you want to have automatic repopulation, minimal CRUD writing and automatic validation: this is the way to go ;-)

    • http://ahermosilla.com Andres Hermosilla

      Having created forms in Laravel & CodeIgnitor I would say I disagree. That’s pretty light on code and easy.

    • http://www.justinscarpetti.com Justin Scarpetti

      I would have to agree with that too!

  • John

    Looking forward to taking a deep dive into this tut on the ride home. Just started to use FuelPHP a few weeks ago and I’m really beginning to see the genius behind it. It would be great to see Jeffrey Way do a video tuts series on FuelPHP.

    • http://echoedlight.com Mitchell Bray

      +1 jeff way fuelphp from scratch

  • Rati

    Thanks for the tutorial, it really provides the insight into the myth of Fieldset class. This really shows me how the Model, Fieldset, Validation, and Form fit and flow together.

    However, from what I’ve tried, setting the ‘label’ of a field in the Model’s _properties array with Lang::get() is not possible and this makes me unable to use it to write the app that support i18n easily. Do you have any suggestion on this?

    Rati

    • http://fuelphp.com Jelmer Schreuder

      Make sure the language file is loaded and enter the lang key as the label, it should translate without trouble.

  • amit

    The amount of coding required to get a form working using FuelPHP defeats the whole purpose. I think the whole objective of a framework is to save time and effort, not to equal or exceed it.

    • Daniel Petrie

      Keep in mind this is only one way to do forms in FuelPHP. There are several way to tackle this.. you can use ORM, Model_CRUD or the query builder in regards to the database layer. You don’t even have to touch the fieldset class if you don’t want to. You can build a standard from with just html and just use the Validation class in a similar form to how CodeIgniter does it if you want to.

  • Jan

    Have you ever tried forms using Nette framework?

    http://doc.nette.org/en/forms

    Automatic validation (javascript is generated, server side validation is automatically made), forms are objects so you don’t mess with arrays..

    form can be automatically generated in presentation layer using one single variable…

    less code, more effectivity

    try it, its fun

  • http://www.get-awebsite.com/ mohammed tantash

    hello and thank you for this lesson but if you don’t mind why not complete this lesson by showing how to automate the whole process of building a form by building a form builder with drag and drop and sorting and saving the form and then generating the output code to be used on a any php website that would be a great followup

  • http://webdesign.seocusco.com Fred

    thanks, these frameworks make me more productive

  • aejnsn

    Good tutorial. I think Oil would have simplified a bit of this tutorial.

    • http://echoedlight.com Mitchell Bray

      personally I’m glad he didn’t i find oil very confusing and over rated (love fuel though)

  • http://www.oystersolaser.net OysterOlaser

    Thanks a lot for this tutorial ! It helps me for my controller problems :)

  • http://namastu.com namastu

    Good One ..

    Thanks

  • http://n/a Tom

    Thanks ! awesome

    made my first fuelphp interaction !

    /me so happy

    *dance dance*

  • http://www.kanqiuwang.com LQ

    我来自中国

  • macjohn

    I think this tutorial has some drawbacks. I’m still thinking why the model has to know how a “field” will be rendered:

    ‘form’ => array(‘type’ => ‘textarea’)

    This stuff belongs to the view. Each view has to know how to draw his content. The model only knows about data.

    Also, as posted abowe, duplicate code in a beginner’s tutorial… To concentrate in the add and edit methods, throw away all the repeated stuff in a private method.

    And I ask myself why in the hell a form description belong to the Controller and not to the View…

    • http://www.thewebsitefactory.com.ar Pablo Rebolini

      +1

    • Tamás Barta

      I think the view shall contain the least possible amount of control logic, so I found this article quite decent. The textarea thing is correct to be stored in the model, because it has a meaning connected to data type, which is most correct in the model.

  • Max Payne

    In tutorial:
    “‘post_status’ => array(
    ‘data_type’ => ‘string’,
    ‘label’ => ‘Post Status’,
    ‘validation’ => array(‘required’),
    ‘form’ => array(‘type’ => ‘select’, ‘options’ => array(1=>’Published’, 2=>’Draft’)),
    )”

    What should I do when my select options need to be taken from another DB table (model) for example from Model_Statuses. It is very simple situation if you don’t describe it then it means that fieldset class gives only false opportunity. Thanks.

  • Mark Hubrouck

    For someone new to Fuel like me it’s refreshing to finally have a tutorial I can understand
    and build on.I realize it might not be perfect for the so called experts out there but I
    don’t believe it’s directed at you anyway. Please do some more of these!