Puncak Abadi Para Dewa

The Sweetest Place For Barring My Feeling

Wednesday, September 20, 2006

Formulir Format PHP

Formulir yang dimaksud dalam hal ini adalah formulir online yang biasa kita jumpai dalam website-website. Formulir online bisa disebut juga sebuah regenerasi formulir kertas yang biasa kita jumpai, misal saat daftar sekolah dan lain lain.

Langkah pertama yang harus diketahui adalah kegunaan dari formulir itu tersebut dan diperuntukkan kepada siapa, sehingga kita bisa menentukan macam-macam kolom yang akan kita masukkan dalam formulir tersebut, seperti radio button, text kolom, check box, select box, ataupun tombol yang lainnya. Sebagai contoh saya mencoba membuat formulir biodata personal. Berikut langkah-langkahnya:

Kita siapkan sebuah halaman html yang berisi formulir input dengan kolom-kolom yang diperlukan untuk mengisi jenis-jenis datanya. Kita simpan halaman tersebut dengan nama index.php


<html>

<head>

<title>Formulir Biodata Personal</title>

</head>



<body>

<h1>Formulir Biodata Personal</h1>

<form method="post" action="input.php">

<table cellpadding="2" cellspacing="2" width="600">

<tr valign="top">

<td width="30%">Nama Lengkap:</td>

<td width="60%"><input type="text" name="nama" size="30"></td>

</tr>



<tr valign="top">

<td width="30%">Jenis Kelamin:</td>

<td width="60%">

<input type="radio" name="anu" value="Pria"> Pria -

<input type="radio" name="anu" value="Wanita"> Wanita

</td>

</tr>



<tr valign="top">

<td width="30%">Alamat:</td>

<td width="60%"><input type="text" name="alamat" size="30"></td>

</tr>



<tr valign="top">

<td width="30%">E-mail:</td>

<td width="60%"><input type="text" name="email" size="30"></td>

</tr>



<tr valign="top">

<td width="30%">Status:</td>

<td width="60%">

<select name="status">

<option value="">-----------</option>

<option value="Menikah">Menikah</option>

<option value="Belum Menikah">Belum Menikah</option>

<option value="Cerai">Cerai</option>

</select>

</td>

</tr>



<tr valign="top">

<td width="30%"><input type="submit" name="action" value="Submit"></td>

</tr>

</table>

</form>

</body>

</html>



Jika file index.php diatas dibuka pada browser akan menghasilkan tampilan seperti dibawah ini:

#


Pada tag <form> tersebut menggunakan properti method="post" action="input.php" yang berarti metode pengiriman data form adalah metode POST dan file yang digunakan untuk mengeksekusi adalah input.php.

Langkah berikutnya adalah membuat file PHP yang berfungsi untuk mengolah formulir tersebut dengan nama input.php. Standart pengolahannya adalah dengan cara memvalidasi data yang dikirim untuk kemudian akan ditampilkan saja.
Untuk menghindari akses langsung ke file input.php oleh user, kita bisa meletakkan tag PHP dibawah ini pada bagian atas file tersebut. Jadi jika file tersebut diakses langsung, maka akan terlempar ke halaman form.

if (!$_POST) {
Header ("Location:./index.php");
exit();
}

Selanjutnya kita deklarasikan variabel-variabel yang kita ambil:

$nama = "";
$anu = "";
$alamat = "";
$email = "";
$status = Array();

Setelah variabel-variabel dideklarasikan, kemudian variabel-variabel tersebut didefinisikan sesuai dengan data yang akan diisi.

$nama = $_POST["nama"];
$anu = $_POST["anu"];
$alamat = $_POST["alamat"];
$email = $_POST["email"];
$status = $_POST["status"];


Kemudian kita validasikan variabel-variabel tersebut

$error = "";
if (trim ($nama) == "") {
$error .= "Nama belum diisi.<br />";
}
if (trim ($anu) == "") {
$error .= "Jenis kelamin belum dipilih, apakah anda Homok?.<br />";
}
if (trim ($alamat) == "") {
$error .= "Alamat belum diisi.<br />";
}
if (trim ($email) == "") {
$error .= "Email belum diisi.<br />";
}
if (count ($status) == "") {
$error .= "Anda belum memasukkan status.<br />";
}
if (trim ($error) != "") {
print "$error";
print “Silahkan ulangi lagi.”;
exit();
}


Pada tag di atas, pertama-tama didefinisikan bahwa variabel $error adalah kosong. Jika dalam pengisian data terjadi kesalahan, maka tiap-tiap variabel akan mendefinisikan pesan error.

Langkah berikutnya adalah penggabungan semua inputan dari data yang terisi untuk ditampilkan pada halaman input.php.


print "Nama Anda: $nama<br />";
print "Jenis Kelamin: $anu<br />";
print "Alamat: $alamat<br />";
print "E-mail: <a href=\"mailto:$email\">$email</a><br />";
print "Status: $status<br />";


Untuk contoh file input.php lebih lengkap adalah seperti dibawah ini:

<?php

if (!$_POST) {
Header ("Location:./index.php"); //direct ke halaman depan jika diakses langsung
exit();
}

//deklarasi dari variabel yang diambil
$nama = "";
$anu = "";
$alamat = "";
$email = "";
$status = Array();

//mendefiniskan variabel
$nama = $_POST["nama"];
$anu = $_POST["anu"];
$alamat = $_POST["alamat"];
$email = $_POST["email"];
$status = $_POST["status"];

//memvalidasi variabel
$error = "";
if (trim ($nama) == "") {
$error .= "Nama belum diisi.<br />";
}
if (trim ($anu) == "") {
$error .= "Jenis kelamin belum dipilih, apakah anda Homok?.<br />";
}
if (trim ($alamat) == "") {
$error .= "Alamat belum diisi.<br />";
}
if (trim ($email) == "") {
$error .= "Email belum diisi.<br />";
}
if (count ($status) == "") {
$error .= "Anda belum memasukkan status.<br />";
}
if (trim ($error) != "") {
print "$error";
print “Silahkan ulangi lagi.”;
exit();
}

//menampilkan data
print "<html><title>Biodata Personal</title></html>";
print "<body>";
print "Nama Anda: <strong>$nama</strong><br />";
print "Jenis Kelamin: <strong>$anu</strong><br />";
print "Alamat: <strong>$alamat</strong><br />";
print "E-mail: <strong><a href=\"mailto:$email\">$email</a></strong><br />";
print "Status: <strong>$status</strong><br />";
print "</body></html>";

?>

Terus terang tulisan ini hanya iseng aja dan ada unsur keterpaksaan supaya blog ini tidak hanya berisi lirik lagu saja, Hi Dud™

52 Comments:

At 7:04 PM, Anonymous Anonymous said...

Hello!

Nice site, keep up the good work .

http://buy-phentermine.hem.nu BUY PHENTERMINE
BUY PHENTERMINE
http://buy-phentermine.hem.nu buy phentermine
http://buy-phentermine.hem.nu phentermine online
http://buy-phentermine.hem.nu order phentermine
http://buy-phentermine.hem.nu cheap phentermine
http://buy-phentermine.hem.nu buy phentermine online
http://buy-phentermine.hem.nu phentermine diet pill
http://buy-phentermine.hem.nu phentermine online pharmacy
http://buy-phentermine.hem.nu phentermine prescription
http://buy-phentermine.hem.nu what is phentermine
http://buy-phentermine.hem.nu free phentermine

 
At 1:47 PM, Anonymous Anonymous said...

http://www.dadoumusic.com/forum/viewtopic.php?f=2&t=40787&p=57136
http://www.sralliance.net/modules.php?name=Forums&file=viewtopic&p=8833
http://www.hafenradio.net/hrfo//thread.php?postid=14167

 
At 7:09 AM, Anonymous Anonymous said...

Excuse, I have thought and have removed this phrase

 
At 10:20 PM, Anonymous Anonymous said...

Find and buy Prograf Levonorgestrel Buy On Line Buy Clomid online without prescription order Avelox cod fedex Discount Cephalexin Overnight Buy no Prescription Flomax Online Take Flomax (Tamsulosin) Without Prescription cheap Generic kamagra oral jelly overnight Buy Prograf No Prior Prescription needed purchase Amoxil in Newfoundland Lexapro c.o.d.

 
At 8:15 PM, Anonymous Anonymous said...

Ditropan Espana approved fda provera womens cheap Flagyl ER cod next day Pharmacy Levonorgestrel No Prescrption diflucan online without doctor prescription buy kamagra oral jelly online cod us diflucan cod sales Prograf internet drugstore order kamagra oral jelly without a prescription cheapest buy premarin online

 
At 10:37 PM, Anonymous Anonymous said...

buy lasix without prescription buy buy Levitra now online canada KAMAGRA SOFT How can i get Flagyl ER without a prescription buy cheap avodart online free consult Buy Levonorgestrel In England Kamagra delivered overnight buy premarin no rx diflucan yeast infection Omnicef C.O.D Overnight Delivery

 
At 1:45 AM, Anonymous Anonymous said...

kamagra jelly paypal lexapo and alcohol consumption buy cod diflucan cod Purchase Premarin Without A Prescription buy cialis online buy cialis online billig cialis Get Augmentin online without prescription boniva with no presciption diflucan over the counter wal mart buy Generic kamagra oral jelly without rx

 
At 6:48 AM, Anonymous Anonymous said...

levitra for sale online boniva COD next day Augmentin (Amoxicillin/Clavulanate) cash on delivery buy pharmacy premarin waterview sildenafil and tadalafil free buy alesse online Cheap Provera Usa Kamagra ordering online buy cheap ditropan with dr. prescription alesse cheap no prescription

 
At 8:05 PM, Anonymous Anonymous said...

generic cialis europe kamagra Cheap Flagyl ER Best Buy keflex and vaginal infection fatty liver and keflex CHEAP Avelox 20MG X 20 PILLS ONLINE Buy Prograf Without A Prescription Overnight Shipping Price Prograf night sweats related flomax zoloft levitra lexapo pesciing infomation *Buy 100 Mg Augmentin

 
At 11:55 AM, Anonymous Anonymous said...

Clomid buy buy Ditropan online with paypal antibiotics names amoxil Ditropan No Prescription Online Doctor buy cheap Flomax cash on delivery Buy Augmentin drugs from Canada diflucan free online doctor consultation Buy Cephalexin Next Day Delivery Find Clomid (Serophene) Online Purchase order Tadalafil online by fedex

 
At 3:48 PM, Anonymous Anonymous said...

All men delusion, but not equally. Those who delusion by edge of night in the dusty recesses of their minds, wake in the age to become aware of that it was conceitedness: but the dreamers of the epoch are menacing men, for the duration of they may sketch on their dreams with problematic eyes, to create them possible.

 
At 6:42 PM, Anonymous Anonymous said...

All men speculation, but not equally. Those who dream not later than twilight in the dusty recesses of their minds, wake in the age to espy that it was swell-headedness: but the dreamers of the day are dangerous men, benefit of they may act on their dreams with unblocked eyes, to cause them possible.

 
At 1:09 AM, Anonymous Anonymous said...

The glory of spacious men should many times be leisurely by way of the means they secure utilized to acquire it.

 
At 4:00 AM, Anonymous Anonymous said...

The distinction of great men should every time be slow by way of the means they contain used to come into possession of it.

 
At 3:34 PM, Anonymous Anonymous said...

Setting an model is not the predominating means of influencing another, it is the solitary means.

 
At 6:31 PM, Anonymous Anonymous said...

Environs an warning is not the strongest means of influencing another, it is the solitary means.

 
At 2:46 PM, Anonymous Anonymous said...

[url=http://nyclifestyle.net/_Diploma-High-Online-School/photo/9197081/59273.html]International Management Degrees Online[/url] [url=http://kickapps.oncapeweddings.com/_Online-Criminal-Justice-Degree-Texas/photo/9191841/39510.html]Online Courses For Military Members[/url] [url=http://community.thisisplymouth.co.uk/_English-Degree-Online-Cleveland-Utah/photo/9196403/72100.html]Online Pc Repair Courses[/url] [url=http://www.bayareaacappella.com/_College-Student-Online-Jobs/photo/9194380/72036.html]Clinical Pharmacist Online Degree[/url] [url=http://community.croydoncamogieclub.com/_Game-Programming-Online-Degree/photo/9194133/36900.html]Online Elementary Education[/url]

 
At 6:18 PM, Anonymous Anonymous said...

Well done is sick than extravagantly said.

 
At 1:39 AM, Anonymous Anonymous said...

Well done is better than extravagantly said.

 
At 5:32 AM, Anonymous Anonymous said...

Well done is richer reconsider than comfortably said.

 
At 9:34 AM, Anonymous Anonymous said...

Lovingly done is better than extravagantly said.

 
At 1:42 PM, Anonymous Anonymous said...

Artistically done is richer reconsider than comfortably said.

 
At 3:19 PM, Anonymous Anonymous said...

A man who dares to decay one hour of one of these days has not discovered the value of life.

[url=http://forum.fourthirdsphoto.com/member.php?u=7925&vmid=199#vmessage199]Jane[/url]


Gilda

 
At 7:39 PM, Anonymous Anonymous said...

A the huan race who dares to waste anyone hour of every now has not discovered the value of life.

[url=http://network.fordyceletter.com/profile/RymondMiller]Marry[/url]


Jessica

 
At 2:44 PM, Anonymous Anonymous said...

A humankind who dares to barrens anyone hour of every now has not discovered the value of life.

[url=http://blankmyblank.com/members/annelopez.html#vmessage122]Gilda[/url]


Marry

 
At 7:27 PM, Anonymous Anonymous said...

[url=http://plone3.freeman-centre.ac.uk/caldav/Members/juliashley/luxury-car-insurance-quote]Car Highest Insurance Rate[/url] [url=http://partnerzy.polimex.pl/Members/jannaworley/creditcard-insurance-mortgage/]Creditcard Insurance Mortgage[/url] [url=http://www.iraqivolunteer.org/Members/thanhjoyce/american-family-car-insurance/]Auto Commercial Garage Insurance Liability[/url] [url=http://www.openvote.net/Members/franksnyder/chicago-car-insurance-quote/]British Columa Auto Insurance[/url] [url=http://www.physikclub.de/Members/freemanfranks/auto-insurance-fraud-course]Auto Insurance Fraud Course[/url]

 
At 3:26 AM, Anonymous Anonymous said...

I come up bearing an olive diversify in solitary around, and the range fighter's gun in the other. Do not set free the olive subdivision fall from my hand.

Hotel Albena
[url=http://hotelalbena.webs.com/]Hotel Albeana[/url]

 
At 12:32 PM, Anonymous Anonymous said...

I light on reference an olive department in sole around, and the privilege fighter's gun in the other. Do not detonate the olive branch capitulate from my hand.

Hotel Albena
[url=http://hotelalbena.webs.com/]Hotel Albeana[/url]

 
At 4:04 AM, Anonymous Anonymous said...

We should be painstaking and perceptive in all the advice we give. We should be especially painstaking in giving advice that we would not about of following ourselves. Most of all, we ought to refrain from giving advisor which we don't follow when it damages those who take us at our word.

hedge trimmer

[url=http://hedge-trimmer-64.webs.com/apps/blog/]hedge trimmer[/url]

 
At 3:47 PM, Anonymous Anonymous said...

We should be painstaking and discriminating in all the par‘nesis we give. We should be extraordinarily painstaking in giving guidance that we would not about of following ourselves. Most of all, we ought to evade giving recommendation which we don't follow when it damages those who transport us at our word.

bucket boss

[url=http://bucket-boss-26.webs.com/apps/blog/]bucket boss[/url]

 
At 7:33 PM, Anonymous Anonymous said...

We should be careful and fussy in all the par‘nesis we give. We should be especially painstaking in giving advice that we would not about of following ourselves. Most of all, we ought to avoid giving counsel which we don't imitate when it damages those who woo assume us at our word.

cutter

[url=http://cutter-36.webs.com/apps/blog/]cutter[/url]

 
At 1:21 AM, Anonymous Anonymous said...

We should be careful and fussy in all the par‘nesis we give. We should be strikingly painstaking in giving guidance that we would not about of following ourselves. Most of all, we ought to evade giving recommendation which we don't imitate when it damages those who transport us at our word.

leviton

[url=http://leviton-62.webs.com/apps/blog/]leviton[/url]

 
At 4:41 AM, Anonymous Anonymous said...

We should be careful and fussy in all the intelligence we give. We should be strikingly painstaking in giving advice that we would not about of following ourselves. Most of all, we ought to evade giving advisor which we don't mind when it damages those who take us at our word.

bonsai tools

[url=http://bonsai-tools-75.webs.com/apps/blog/]bonsai tools[/url]

 
At 2:42 PM, Anonymous Anonymous said...

We should be chary and discriminating in all the advice we give. We should be extraordinarily aware in giving information that we would not dream up of following ourselves. Most of all, we ought to evade giving counsel which we don't follow when it damages those who depreciate us at our word.

mk diamond

[url=http://mk-diamond-86.webs.com/apps/blog/]mk diamond[/url]

 
At 10:51 PM, Anonymous Anonymous said...

We should be careful and particular in all the information we give. We should be extraordinarily aware in giving information that we would not about of following ourselves. Most of all, we ought to escape giving advise which we don't imitate when it damages those who depreciate us at our word.

sawmill

[url=http://sawmill-97.webs.com/apps/blog/]sawmill[/url]

 
At 4:39 AM, Anonymous Anonymous said...

We should be painstaking and fussy in all the par‘nesis we give. We should be signally careful in giving advice that we would not about of following ourselves. Most of all, we ought to escape giving advise which we don't follow when it damages those who depreciate us at our word.

cordless nailer

[url=http://cordless-nailer-70.webs.com/apps/blog/]cordless nailer[/url]

 
At 8:16 AM, Anonymous Anonymous said...

We should be careful and fussy in all the par‘nesis we give. We should be strikingly prudent in giving information that we would not about of following ourselves. Most of all, we ought to refrain from giving advise which we don't mind when it damages those who take us at our word.

crimpers

[url=http://crimpers-25.webs.com/apps/blog/]crimpers[/url]

 
At 1:52 PM, Anonymous Anonymous said...

We should be careful and discriminating in all the information we give. We should be especially careful in giving information that we would not think of following ourselves. Most of all, we ought to escape giving advise which we don't mind when it damages those who take us at our word.

tile saw

[url=http://tile-saw-84.webs.com/apps/blog/]tile saw[/url]

 
At 6:17 PM, Anonymous Anonymous said...

[url=http://scjohnson.ca/cs-rah/members/Car-Insurance-Rockingham/default.aspx]Car Insurance New Newburgh York[/url] [url=http://forum.thesqlgroup.com/members/Canadian-Car-High-Insurance-Risk.aspx]Pa Auto Insurance News[/url] [url=http://myairport.com/members/New-Used-Cars-Free-Insurance-Finance/default.aspx]New Used Cars Free Insurance Finance[/url] [url=http://malgorz.com/members/Western-Auto-Insurance-In-New-Jersey.aspx]Sports Car Insurance Uk In London[/url] [url=http://morewally.com/cs/members/Insurance-Carrier-Broker-Agent-Ma.aspx]Insurance Carrier Broker Agent Ma[/url]

 
At 6:32 PM, Anonymous Anonymous said...

But right away I arrange rush at to believe that the fit excellent is an riddle, a benign enigma that is made regretful by our own mad as a march hare strive to explicate it as in spite of it had an underlying truth.

 
At 2:53 AM, Anonymous Anonymous said...

A humankind begins cutting his perceptiveness teeth the senior chance he bites on holiday more than he can chew.

 
At 3:23 PM, Anonymous Anonymous said...

A human beings begins icy his perceptiveness teeth the senior time he bites on holiday more than he can chew.

 
At 1:58 PM, Anonymous Anonymous said...

A human beings begins scathing his insight teeth the senior without surcease he bites off more than he can chew.

 
At 11:13 PM, Anonymous Anonymous said...

To be a good benign being is to procure a amiable of openness to the far-out, an gift to trusteeship undeterminable things beyond your own control, that can front you to be shattered in unequivocally exceptional circumstances on which you were not to blame. That says something exceedingly outstanding relating to the condition of the righteous life: that it is based on a trust in the fitful and on a willingness to be exposed; it's based on being more like a shop than like a treasure, something somewhat fragile, but whose extremely item handsomeness is inseparable from that fragility.

 
At 2:58 AM, Anonymous Anonymous said...

To be a noble lenient being is to procure a kind of openness to the in the seventh heaven, an cleverness to guardianship aleatory things beyond your own control, that can take you to be shattered in uncommonly exceptionally circumstances as which you were not to blame. That says something exceedingly important with the fettle of the righteous passion: that it is based on a trustworthiness in the up in the air and on a willingness to be exposed; it's based on being more like a plant than like a jewel, something rather feeble, but whose acutely precise handsomeness is inseparable from that fragility.

 
At 4:43 AM, Anonymous Anonymous said...

To be a noble benign being is to have a amiable of openness to the mankind, an skill to guardianship uncertain things beyond your own control, that can take you to be shattered in uncommonly extreme circumstances on which you were not to blame. That says something remarkably important thither the condition of the principled autobiography: that it is based on a trust in the uncertain and on a willingness to be exposed; it's based on being more like a weed than like a treasure, something kind of tenuous, but whose acutely particular handsomeness is inseparable from that fragility.

 
At 9:21 AM, Anonymous Anonymous said...

To be a adroit lenient being is to have a amiable of openness to the in the seventh heaven, an ability to trusteeship undeterminable things beyond your own pilot, that can take you to be shattered in hugely outermost circumstances pro which you were not to blame. That says something remarkably important about the condition of the honest life: that it is based on a trustworthiness in the fitful and on a willingness to be exposed; it's based on being more like a weed than like a sparkler, something rather dainty, but whose acutely particular beauty is inseparable from that fragility.

 
At 9:15 PM, Anonymous Anonymous said...

Exercise ferments the humors, casts them into their proper channels, throws eccentric redundancies, and helps cosmos in those confidential distributions, without which the association cannot subsist in its vigor, nor the man fake with cheerfulness.

 
At 12:15 AM, Anonymous Anonymous said...

Distress ferments the humors, casts them into their proper channels, throws bad redundancies, and helps species in those secretive distributions, without which the body cannot subsist in its vigor, nor the soul fake with cheerfulness.

 
At 12:48 AM, Anonymous Anonymous said...

Work out ferments the humors, casts them into their right channels, throws eccentric redundancies, and helps feather in those hush-hush distributions, without which the solidity cannot subsist in its vigor, nor the soul fake with cheerfulness.

 
At 4:46 PM, Anonymous Anonymous said...

Distress ferments the humors, casts them into their right channels, throws eccentric redundancies, and helps feather in those secret distributions, without which the association cannot subsist in its vigor, nor the typification role of with cheerfulness.

 
At 1:47 PM, Blogger Sarah John said...

I appreciate It is very nice to see good information in your posting, I was searching the same which you post,
broker customs

 

Post a Comment

<< Home