PW1 05-Form+IntroPHP PDF
PW1 05-Form+IntroPHP PDF
Pemrograman Web 1
05- Form and Introduction to PHP
HTML FORM
HTML Form
draws a box around the related elements
defines a caption for the <fieldset> element
Attribute <form>...</form>
Value
Description
name
Text
method
GET/POST
action
URL/nama file
Method GET/POST
GET
Useful for form submissions where a user want to bookmark the result
Display the form contents from the user
Have a limit to how much data you can place in a URL (varies between
browsers)
Never use the "get" method to pass sensitive information!
http://localhost/form_login/proses_login.php?uname=nama_user&pwd=pass_user
POST
HTML Form-Input
An input field can vary in many ways, depending on the type attribute
the <input> tag requires a name, the name of the <input> tag allows the
programmer to work with the data from the control
Value
Description
name
Text
type
Type
value
Text
Define a single-line text field that a user can enter text into
Value
Description
size
Number
maxlength
Text
Character limit
Value
Description
size
Number
maxlength
Text
Character limit
Type Submit
a series of controls that allow multiple selections. Users pick their choices by
placing a check mark in the box.
<input type = "..." name="..." value="...">
Buah Fav. :
<input type=checkbox" name="buah" value="apel"> Apel
<input type="checkbox" name="buah" value="jeruk" checked> Jeruk
<input type="checkbox" name="buah" value="jambu"> Jambu
<input type="checkbox" name="buah" value="anggur"> Anggur
a series of controls from which the user can select one choice.
<input type = "..." name="..." value="...">
Jenis Kelamin :
<input type=radio" name="jns_kelamin" value="p" checked> Perempuan
<input type=radio" name="jns_kelamin" value="l"> Laki-Laki
Define a hidden field (not visible to a user). A hidden field often store a default
Type File
Allows the user to browse to a file on their machine for submission to the web
site.
Gambar : <input type=file" name="upload" />
Type Button
Drop-down lists are a good method to deliver a large range of choices without
taking a lot of screen space.
If you have a long list of options, groups of related options are easier to handle
for a user.
<html>
<body>
<select>
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
</body>
</html>
A text area can hold an unlimited number of characters, and the text renders
in a fixed-width font (usually Courier).
The size of a text area is specified by the cols and rows attributes.
<textarea name="..." rows="..." cols="..."> ... </textarea>
Attribute
Value
Description
rows
Number
cols
Number
Introduction to PHP
XAMPP
Open Source
2 type of MySQL :
MySQL
XAMPP
PHP File
PHP code is not displayed when user view source from browser
PHP Syntax
A PHP script always starts with <?php and ends with ?>. A PHP script can
be placed anywhere in the document.
Each code line in PHP must end with a semicolon. The semicolon is a
separator and is used to distinguish one set of instructions from another.
PHP Variables
Comments in PHP
The concatenation operator (.) is used to put two string values together.
HTML in PHP
PHP Operators
Arithmetic Operators
+ - * / % ++ --
Assignment Operators
= += -= *= /= %=
Comparison Operators
== != <> > >= < <=
Logical Operators
&& || !
When the user clicks the "Submit" button, the URL sent to the server could look something
like this:
http://localhost/form_login/proses_login.php?uname=wenny&pwd=wenny
Example :
login.php
proses_login.php
When the user clicks the "Submit" button, the URL will look like this:
http://localhost/form_login/proses_login.php
Exercise 1
Exercise 2
Buatlah tampilan form seperti dibawah ini. Ketika tombol Simpan ditekan,
tampilkan data yang telah dimasukan oleh user.
Field tahun hanya dapat diisi 4 karakter