Catching Parameters - Meeting 5

In this lesson, we are learning on catching parameters from another page. So we will have 2 files as examples, the first is containing a form in which will be submitted to another page. The second is the file which will catch the first page/file.

Here is the first script:

Please fill your username and password in this registration form below
<form action="five.php" method="post">
Nama : <input type="text" name="usrname" size="30" maxlength="30"><br><br>
Password : <input type="password" name="passwd" size="8" maxlength="8"><br><br>
<input type="submit" value="Send Soon!">

In the script above we only apply html codes as we ignore some security aspects for this basic lesson. The most important thing is the parameter action="name.php" method="post" inside form tag, name="usrname" and name="passwd" because those parameters will be catchedby the next file/page.
Save the file as four.php

Next, here is the second script:

<center><h3>Form Destination</h3></center>
<h4>Thank you for submitting your registration form</h4>
We have completely received your registration form
$username = $_POST['usrname'];
$passwd = $_POST['passwd'];
print("Your username is <b>$usrname</b><br>");
print("Your password is <i>$passwd</i><br>");

The file above must be saved as five.php. Why? It s because a page/file where the first file was addressed (see action="five.php" in the previous script). Then we catch the other two parameters with a command $_POST['...']. We are using "POST" because in the first file we used POST method. Basically we may use POST or GET method.

No comments: