PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


Table of Content
Learn CodeIgniter Framework Tutorial

Learn CodeIgniter Basic
CI Framework
CI Installation
CI MVC
CI Parameter
CI GET
CI Database Config
CI Database
CI Show All Data
CI Show a Data
CI GET Data

Learn CodeIgniter Form
CI Skeleton
CI Structure
CI Layout
CI Menu
CI Text
CI Centralizing
CI CSS
CI HTML
CI Form Code
CI HTML Style
CI Table
CI Insert Data
CI Table Library
CI Table List
CI URL Helper
CI Single Data
CI Form Parameters
CI Updating Data
CI Deleting Data

PHP Error Message

Warning: Invalid argument supplied for foreach() in /home/a3178292/public_html/article.php on line 213

Free Web Hosting

CodeIgniter - Form: Creating Form HTML


CodeIgniter Form Step By Step Tutorial - Part 8: Now, we begin create a form for input data. We will use HTML Form CodeIgniter style. It is more save your time!

First, we need load Form helper. Put at controller (books.php within CodeIgniter\system\application\controllers), input() method. You can see line 16 at following code

<?
class Books extends Controller{

  function Books(){
	parent::Controller();
  }
	
  function main(){
	$this->load->model('books_model');
	$data = $this->books_model->general();
		
	$this->load->view('books_main',$data);
  }
	
  function input(){
	$this->load->helper('form');  
	$this->load->model('books_model');
	$data = $this->books_model->general();
				
	$this->load->view('books_input',$data);	
  }
}
?>	

Open "books_input.php" within CodeIgniter\system\application\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; ?>: 
<? echo form_input('title'); ?>
</br>
<? echo $author; ?>: 
<? echo form_input('author'); ?>
</br>
<? echo $publisher; ?>: 
<? echo form_input('publisher'); ?>
</br>
<? echo $year; ?>: 
<? echo form_dropdown('year',$years); ?>
</br>
<? echo $available; ?>: 
<? echo form_checkbox('available','yes',TRUE); ?>
</br>
<? echo $summary; ?>: 
<? echo form_textarea('summary'); ?>
</br>
<? echo form_submit('mysubmit','Submit!');  ?>
<? echo form_close(); ?>

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

</body>
</html>

Do You can feel its difference with ordinary HTML? Yup, it more simple and save your time. The code still not work. We must define parameters at model.

Edit your model, and add parameter

<?
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';		
		
	return $data;	
  }
}
?>

Now, point your browser to http://localhost/CodeIgniter/index.php/books/input. May be you will get like this:

CodeIgniter form HTML


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


Tag: CodeIgniter, framework, MVC, form, HTML Category: PHP Framework Post : February 24th 2008 Read: 11,731 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration