phpeveryday.com

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


CodeIgniter - Form: Something Happen With Form Parameters

Tag: CodeIgniter, framework, MVC, form, parameter   Category: PHP Framework
post: 03 Mar 2008 read: 2,346


CodeIgniter Form Step By Step Tutorial - Part 17: At previous post, we talk about creating edit form. This form is normal when we sent a parameter get to show single data. But, when we didn't send any value, it raise error. Why?

Ok, try open form with http://localhost/CodeIgniter/index.php/books/input

codeigniter form error

Yes, you can guess what happen. We didn't declare two parameter: $fid and $fyear. We define when there is id at GET. See again following controller:


  function input($id = 0){

	$this->load->helper('form');  
	$this->load->helper('html');  	
	$this->load->model('books_model');
	
	if($this->input->post('mysubmit')){
	  $this->books_model->entry_insert();
	}
	$data = $this->books_model->general();
	
    if((int)$id > 0){
      $query = $this->books_model->get($id);
	  $data['fid']['value'] = $query['id'];
	  $data['ftitle']['value'] = $query['title'];
	  $data['fauthor']['value'] = $query['author'];
	  $data['fpublisher']['value'] = $query['publisher'];
	  $data['fyear']['value'] = $query['year'];
	  if($query['available']=='yes'){
	    $data['favailable']['checked'] = TRUE;
	  }else{
	    $data['favailable']['checked'] = FALSE;	  
	  }
	  $data['fsummary']['value'] = $query['summary'];
	}
	
				
	$this->load->view('books_input',$data);	
  }

So we must crate bait. I create it at model by add 2 line (13 & 14):


  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['fid']['value']		= 0;
	$data['fyear']['value']		= 0;
		
	$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['forminput']	= 'Form Input';
	
	$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;	
  }

Our form become normal again.



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