phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


CodeIgniter - Form: Creating Beautiful Form Code

Tag: CodeIgniter, framework, MVC, form, HTML   Category: PHP Framework
post: 24 Feb 2008 read: 3,124


CodeIgniter Form Step By Step Tutorial - Part 9: We have learned create form at previous post. Now, we will modify that code in order to more clean and beautiful.

First, open again your "books_input.php" within views. Update like following code:


<html>
<head>
<link rel="stylesheet" type="text/css" 
      href="<?php echo "$base/$css"?>">
</head>
<body>
<div id="header">
<? $this->load->view('books_header'); ?>
</div>
<div id="menu">
<? $this->load->view('books_menu'); ?>
</div>

<? echo form_open('books/input'); ?>
<? echo $title		.' : '.form_input($ftitle); ?></br>
<? echo $author		.' : '.form_input($fauthor); ?></br>
<? echo $publisher	.' : '.form_input($fpublisher); ?></br>
<? echo $year		.' : '.form_dropdown('year',$years); ?></br>
<? echo $available	.' : '.form_checkbox($favailable); ?></br>
<? echo $summary	.' : '.form_textarea($fsummary); ?></br>
<? echo form_submit('mysubmit','Submit!');  ?>
<? echo form_close(); ?>

<div id="footer">
<? $this->load->view('books_footer'); ?>
</div>

</body>
</html>

You can see such as line 15. Before, we write like this


form_input('title');

Now, we write like this:


form_input($ftitle);

Why we do this? Because we want to control parameters for <input> tag. We will add parameters like this


$data['ftitle']		= array('name'=>'title',
	                            'size'=>30
						  );

Can you see what I mean? Ok, for more clear, update your model like following code:


<?
class books_model extends Model{
	
  function books_model(){
	parent::Model();
	$this->load->helper('url');				
  }
	
  function general(){
	$this->load->library('MyMenu');
	$menu = new MyMenu;
	$data['base']		= $this->config->item('base_url');
	$data['css']		= $this->config->item('css');		
	$data['menu'] 		= $menu->show_menu();
	$data['webtitle']	= 'Book Collection';
	$data['websubtitle']= 'We collect all title of 
		                   books on the world';
	$data['webfooter']	= '© copyright by step 
		                   by step php tutorial';
						   
	$data['title']	 	= 'Title';
	$data['author']	 	= 'Author';
	$data['publisher']	= 'Publisher';				
	$data['year']	 	= 'Year';
	$data['years']	 	= array('2007'=>'2007',
	                            '2008'=>'2008',
								'2009'=>'2009');	
	$data['available']	= 'Available';	
	$data['summary']	= 'Summary';
	
	$data['ftitle']		= array('name'=>'title',
	                            'size'=>30
						  );
	$data['fauthor']	= array('name'=>'author',
	                            'size'=>30
						  );
	$data['fpublisher']	= array('name'=>'publisher',
	                            'size'=>30
						  );
        $data['favailable']	= array('name'=>'available',
	                            'value'=>'yes',
								'checked'=>TRUE
						  );
	$data['fsummary']	= array('name'=>'summary',
	                            'rows'=>5,
								'cols'=>30
						  );
    return $data;	
  }
}
?>

See line 29 and rest. You will understand what I mean. It is more simple and clearly to write HTML code.

codeigniter form code


Series this article:
CodeIgniter - Form: Creating Skeleton
CodeIgniter - Form: File Structure
CodeIgniter - Form: Creating Layout Code
CodeIgniter - Form: Creating Menu Library
CodeIgniter - Form: Putting Text at Header and Footer
CodeIgniter - Form: Centralizing $data
CodeIgniter - Form: Adding CSS
CodeIgniter - Form: Creating Form HTML
CodeIgniter - Form: Creating Beautiful Form Code
CodeIgniter - Form: CodeIgniter HTML Style
CodeIgniter - Form: Preparing Table at Database
CodeIgniter - Form: Creating Insert Data
CodeIgniter - Form: Creating List Data Use Table Library
CodeIgniter - Form: Creating Table List Without Table Library
CodeIgniter - Form: Using URL Helper
CodeIgniter - Form: Showing Single Data for Form Edit
CodeIgniter - Form: Something Happen With Form Parameters
CodeIgniter - Form: Updating Data
CodeIgniter - Form: Deleting Data

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


619
posting