Professional Documents
Culture Documents
5-Form Control For Passing Value
5-Form Control For Passing Value
Chapter 5
-2-
ផលសេ%មចរ ំពឹងទុនៃនេមេរ1ន
Ø ករេ$បី Method នង
ិ Action របស់ Form
Ø ករទទួលតៃម2ពី Method GET នង
ិ POST
Ø Form Validation
Ø Form Require Fields
Ø កររក5តៃម2ទុកកនុង Form េពល Submit
Ø េចះេ$បី Session នង
ិ Cookie
Ø ករេ$ប$ី បស់ File
-3-
ករ%បមូលទិននន័យេចញពី Form
-4-
ករេ%ប%បស់ GET
-5-
ករេ%ប%បស់ POST
-6-
Form Required Fields
Ø េនេពលេយង
ី បេងកីត Form មួយេដីមប$ី បមូលព័ត៌មន េហយ
ី Field
ខ2ះទមទរ$តVវែតបញចូ លiច់ខតមន
ិ Xចខkះបន ដូេចនះេយង
ី Xច
កំណត់ Validation ឱយ Field ទំងេនះេនេពលែដលមន
ិ បញចូ លdនង
ឹ
បងPញ Message $បប់ឱយអនកបញចូ លបនដឹង។
Ø empty(variable) $តmតពន
ិ ត
ិ យេមល
ី Variable ទេទរឬអត់។ តៃម2
ែដលចត់ទុកថ empty មនដូចជ 0, 0.0, "0", "", NULL, FALSE,
array()
-7-
Form Required Fields
-8-
Forms Validate Name E-mail and URL
-9-
កររក?ទិននន័យទុកកនង
ុ Form េពល Submit
Ø េនេពលែដលេយង
ី បនបញចូ ល$គប់ Field ទំងអស់បន$តម
ឹ $តVវHម
ករកំណត់ Validation េហយ
ី េនះ េដីមបប
ី ងPញ តៃម2េនកនុង Field
នម
ី ួយៗបនទប់ពី User បនចុច Submit Form េយង
ី $តVវសរេសរ
PHP Script បែនថមេនកនុង Value Attribute របស់ Field នីមួយៗ
េដម
ី បច
ី ប់យកតៃម2បញចូ លកនុង Field ទំងេនះ។
-10-
កររក?ទិននន័យទុកកនង
ុ Form េពល Submit
-11-
ករសិក?ពី Cookies
Ø Cookie គជ
ឺ File តូចមួយែដល Server បេងកីតdេនេលី Browser
េហយ
ី រក5dទុកកនុងកុំពយូទ័ររបស់អនកេ$ប$ី បស់។ ជទូេទេគេ$បd
ី
ស$មប់សមគល់ User។ ឧទហរណ៍ដូចជករចងចំ Username
នង
ិ Password ជេដម
ី ។
-12-
ករសិក?ពី Cookies
Ø ករបេងកីត Cookie
setcookie(name, value, expire)
Ø ករែកតៃម2 Cookie
setcookie(name, value, expire)
Ø ករលុប Cookie
setcookie(“name", "", time() - 3600) // expire 1 hour ago
Øេដីមបa
ី ប់ចំនួន Cookie បនបេងកីត
count ($_COOKIE)
-13-
ករសិក?ពី Sessions
Ø Session គជ
ឺ កររក5ទុកព័ត៌មនកនុង Variable េដីមបX
ី េ$ប$ី បស់
ឆ2ងេទ Page េផzងេទ{តបន។
Ø Session Xចរក5ទុកតៃម2បនែតេពលែដល Browser កំពុងែតេបក
ី
ប៉ុេ[\ះ េនេពលបិទ Browser dនឹងលុបេចលេiយសk័យ$បវតEិ។
-14-
ករសិក?ពី Sessions
Ø ករបេងកីត Session
session_start() // Start Session
$_SESSION[‘var-name’] // Set Variable to Session
Øករែកតៃម2 Session
េដីមបែី កតៃម2របស់ Session $គន់ែតសរេសរតៃម2ថមីជន់េលីតៃម2ចស់
Ø ករលុប Session
session_unset() // Remove all session variable
session_destroy() // Destroy the session
-15-
ដំេណរករ PHP ជមួយ File
Ø Open File
fopen(“file”, “modes”)
Ø Close File
fclose(filename)
ØRead File
fread(filename, filesize(“file”))
Ø Create File
fopen(“filename”, “w”)
ØWrite File
fwrite(“filename”, “text”)
-16-
File Modes
Modes Description
r Open a file for read only. File pointer starts at the beginning of the file
w Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist.
File pointer starts at the beginning of the file
a Open a file for write only. The existing data in file is preserved. File pointer starts at the end of
the file. Creates a new file if the file doesn't exist
x Creates a new file for write only. Returns FALSE and an error if file already exists
r+ Open a file for read/write. File pointer starts at the beginning of the file
w+ Open a file for read/write. Erases the contents of the file or creates a new file if it doesn't
exist. File pointer starts at the beginning of the file
a+ Open a file for read/write. The existing data in file is preserved. File pointer starts at the end
of the file. Creates a new file if the file doesn't exist
x+ Creates a new file for read/write. Returns FALSE and an error if file already exists
-17-
THANK YOU J
-18-
-19-