기본 콘텐츠로 건너뛰기

CodeIgniter GET And POST Form Input Method

CodeIgniter GET And POST Form Input Method

Programming/PHP

In this tutorial we will give you brief description about CodeIgniter input post, this is most important part of a web application.

It uses an input class of CodeIgniter that provides some helper functions that helps to fetch data and to pre-process it.

Form submit can done with two input methods, GET and POST. In this blog, we use default method POST for submit form.

CodeIgniter doesn't support GET method as natively. To use GET method, you have to use normal HTML form.

Syntax:

$this - > input - > post ( ) ; $this - > input - > get ( ) ; $this - > input - > get_post ( ) ;

Setting Up Codeigniter – Configuration Files

Setting up Base url for your file path.

Open "application\config\config.php" file and set the path as given below $config [ 'base_url' ] = 'http://localhost/form_submit/' ;

Open "application\config\config.php" file and set the path as given below Setup helper function that helps you to load form tags.

Open "application\config\autoload.php" and set the 'form' in helper array. $autoload [ 'helper' ] = array ( 'form' ) ;

Example #1 - Sample HTML Form 이름: 연령:

How To Run File

Run the program using basepath as class name and function name, for example :

http : / / localhost / form_submit / index . php / form / form_show

Tutorial Scripts in detail

Below are the details of the code used in this tutorial with proper explanation.

Form Submission Using Post Method

Now I am going to create a form that use POST method. We know that CodeIgniter contains controller, model and view files. Let's start with controller.

Controller file : form.php

This file helps you to load forms in view page, data submitted on the view page will be catched and then data again displayed on the view part.

load - > view ( "view_form" ) ; } public function data_submitted ( ) { $data = array ( 'user_name' = > $this - > input - > post ( 'u_name' ) , 'user_email_id' = > $this - > input - > post ( 'u_email' ) ) ; $this - > load - > view ( "view_form" , $data ) ; } } ?>

View file : view_form.php

< html > < head > < title > Codeigniter Form Submit Using Post and Get Method < link rel = " stylesheet " type = " text/css " href = " css/style.css " > < body > < div class = " main " > < div id = " content " > < h3 id = 'form_head' > Codelgniter Form Submit < br /> < div id = " form_input " > 'u_name' , 'placeholder' = > 'Please Enter User Name' , 'class' = > 'input_box' ) ; echo form_input ( $data ) ; echo form_label ( 'User email:' , 'u_email' ) ; $data = array ( 'type' = > 'email' , 'name' = > 'u_email' , 'placeholder' = > 'Please Enter Email Address' , 'class' = > 'input_box' ) ; echo form_input ( $data ) ; ?> < div id = " form_button " > 'submit' , 'value' = > 'Submit' , 'class' = > 'submit' ) ; echo form_submit ( $data ) ; ?> " ; echo " < h3 id = 'result_id' > You have submitted these values < br /> < hr > " ; echo " < div id = 'result_show' > " ; echo " < label class = 'label_output' > Entered User Name : " . $user_name ; echo " < label class = 'label_output' > Entered Email : " . $user_email_id ; echo " < div > " ; echo " " ; } ?>

CSS File: style.css

Here is the CSS file, which is used in form.

body { font-family : 'Raleway' , sans-serif ; } .main { width : 1015px ; position : absolute ; top : 10% ; left : 20% ; } #form_head { text-align : center ; background-color : #FEFFED ; height : 66px ; margin : 0 0 -29px 0 ; padding-top : 35px ; border-radius : 8px 8px 0 0 ; color : rgb (97, 94, 94) ; } #content { position : absolute ; width : 450px ; height : 356px ; border : 2px solid gray ; border-radius : 10px ; } #content_result { position : absolute ; width : 450px ; height : 192px ; border : 2px solid gray ; border-radius : 10px ; margin-left : 559px ; margin-top : -262px ; } #form_input { margin-left : 50px ; margin-top : 36px ; } label { margin-right : 6px ; font-weight : bold ; } #form_button { padding : 0 21px 15px 15px ; position : absolute ; bottom : 0px ; width : 414px ; background-color : #FEFFED ; border-radius : 0px 0px 8px 8px ; border-top : 1px solid #9A9A9A ; } .submit { font-size : 16px ; background : linear-gradient (#ffbc00 5%, #ffdd7f 100%) ; border : 1px solid #e5a900 ; color : #4E4D4B ; font-weight : bold ; cursor : pointer ; width : 300px ; border-radius : 5px ; padding : 10px 0 ; outline : none ; margin-top : 20px ; margin-left : 15% ; } .submit:hover { background : linear-gradient (#ffdd7f 5%, #ffbc00 100%) ; } .label_output { color : #4A85AB ; margin-left : 10px ; } #result_id { text-align : center ; background-color : #FCD6F4 ; height : 47px ; margin : 0 0 -29px 0 ; padding-top : 12px ; border-radius : 8px 8px 0 0 ; color : rgb (97, 94, 94) ; } #result_show { margin-top : 35px ; margin-left : 45px ; } .input_box { height : 40px ; width : 240px ; padding : 20px ; border-radius : 3px ; background-color : #FEFFED ; }

Form Submission Using Get Method

CodeIgniter doesn't support GET method natively. So we have to use normal HTML form code.

< form action = " form/data_submitted " method = " get " > User Name :: < input type = " text " name = " u_name " placeholder = " Please Enter User Name " class = " input_box " > User email: < input type = " text " name = " u_email " placeholder = " Please Enter Email Address " class = " input_box " > < input type = " submit " value = " Submit " class = " submit " >

Values receive as array using GET in Controller.

public function data_submitted ( ) { $data = array ( 'user_name' = > $this - > input - > get ( 'u_name' ) , 'user_email_id' = > $this - > input - > get ( 'u_email' ) ) ;

Conclusion

Thanks for reading complete post. Hope you enjoyed learning. You can share your views in the space provided below and get in touch with us.

출처 : https://www.formget.com/codeigniter-form-input/

from http://sugerent.tistory.com/534 by ccl(A) rewrite - 2020-03-06 04:54:36

댓글

이 블로그의 인기 게시물

[PHP] 코드이그니터 - 파일업로드 구현

[PHP] 코드이그니터 - 파일업로드 구현 파일 업로드 이번에 PHP 프레임워크인 코드 이그니터(Codeigniter)를 사용하여 홈페이지를 만드는데 사용한 이미지 업로드용 코드 입니다. upload 라이브러리를 사용하고 app~ 와 같은 위치에 upload 폴더를 만드고 다음 코드를 사용한다음 ajax 로 호출하여 파일을 업로드 합니다. function index() { // Upload 설정 $config['upload_path'] = './upload/'; $config[\'allowed_types\'] = 'gif|jpg|png'; $config['max_size'] = 100; // 100k $config['max_width'] = 1024; $config['max_height'] = 768; $this->load->library('upload', $config); $data = array(); if (! $this->upload->do_upload("service_image")) { $error = array('error' => $this->upload->display_errors()); } else { //$data = array('upload_data' => $this->upload->data()); $this->output->set_output("./upload/".$this->upload->data('file_name')); } } jquery 를 이용한 파일 업로드 호출 코드 function upload() { var datas, xhr; datas = new FormData(); datas.append( 'service_image', $( ...

2017년 1월 스타트업에서 구인할때 주로 원하는 개발 기술

2017년 1월 스타트업에서 구인할때 주로 원하는 개발 기술 php mysql linux android git kotlin gcm/fcm python mssql mongodb amazon aws ios objective-c swift github python c++ django python postgresql amazon aws html5/css3/javascript android java mysql python c++ c# java aws cloud-server dbms node.js postgresql redis nginx react.js hapi.js amazon aws restful-api angularJS jQuery html5/css3/javascript android firebase custom ui component restful-api asp.net c# html css javascript bootstrap angularjs node.js php mongodb redis 프론트엔드 주요 기술 javascript jquery ajax angularjs wbesocket html5/css3/javascript android ios java xcode node.js coffeescript mysql amazon ec2 amazon es3 android ios node.js php python java ios php mysql apache python android redis node.js jquery msa node.js java restful-api linux nosql golang redis nginx ...

이클립스 코드이그나이터 연동 ( eclipse codeigniter )

이클립스 코드이그나이터 연동 ( eclipse codeigniter ) https://ellislab.com/codeigniter/user-guide/installation/downloads.html 위의 사이트에서 코드이그나이터를 다운 받는다. 다운받은 압축 파일을 풀어 준다. 이클립스에서 php 프로젝트를 생성한 공간에 코드이그나이터 압축파일을 복사 붙여넣기 해준다. 위와 같은 화면이 나오면 정상적으로 연동이 된 것 입니다. from http://nahosung.tistory.com/22 by ccl(A) rewrite - 2020-03-06 16:20:55