sangkrit

Creating and Managing Forms (Input Fields , Input Characters , Radio & Submit Buttons etc)


Forms are coded with HTML. A form comprises of input fields i.e. the input areas block used by the user for inputting information. We use text characters for inputting the information which is having parameter of the accepted input characters. Radio buttons and check boxes are also used in creating a form. Radio buttons are used for inputting an individual choice while check boxes can input multiple choices by the user.

Other than this, passwords are prepared for hiding the text which the user is typing without changing the value of the characters inputted.

Drop-down boxes are also the common features used in most of the forms for selecting the different choices. Like most sites provides this feature for selecting a country, city etc. This feature is useful in providing a user to choose from a given list.

Submit buttons are used for the final decision given by the user for the processing after the user input his information.

For understanding it practically we will modify our lamp1.php file:

<?php

 

session_start ();

 

$_SESSION[‘username’] = $_POST [‘user’];

$_SESSION[‘userpass’] = $_POST [‘pass’];

$_SESSION[‘authuser’] = 0;

 

if (($_SESSION[‘username’] == ‘123abc’) and

($_SESSION[‘userpass’] = ‘12345’)) {

$_SESSION[‘authuser’] = 1;

 

}

else {

echo ‘permission denied’;

exit ();

}

 

<html>

<head>

<title>Another lamp site</title>

</head>

</body>

 

<?php

echo ‘<a href=”lamp.php?lamp_post=L.A.M.P.”>’;

echo ‘click here to see lamp page’;

echo’</a>;

?>

 

</body>

</html>

 

Now open lamp.php file and modify it according to this:

<?php

 

session_start ();

if ($_SESSION[‘authuser’] ! = 1 {

echo ‘no logging permission for this page’;

 

exit ();

}

?>

 

<html>

<head>

<title>LAMP Site – <?php echo $GET[‘lamp_post’]; ?></title>

</head>

<body>

 

<?php

echo ‘Hello’];

echo $_SESSION[‘username’];

echo ‘<br/>;

?>

</body>

</html>

 

Now open text editor for a new file name login.php.

<?php

session_unset ();

?>

<html>

<head>

<title> Log in </title>

</head>

<body>

<form method=”post” action=”lamp1.php”>

<p>Enter Username:

<input type=”text” name=”user”/>

</p>

<input type=”password” name=”pass”/>

</p>

<input type=”submit” name=”submit” value=”Submit”/>

</p>

</form>

</body>

</html>

 

As you have save this file as login.php, now open this file in a browser there you will see space for you username and password with a submit button. Entering the correct username and password will take you to the page lamp1.php.In case if you enter the wrong username and password then you will receive the message, “no logging permission for this page.” Due to the statement: session_start ();

 

if ($_SESSION[‘authuser’] ! = 1 {

echo ‘no logging permission for this page’;

exit ();

 

When you will enter your password in the form, it will show ***** characters due to the tag: <input type=”password” name=”pass”/>. Here the input type is password which is the reason why the page is showing you ***** characters.

On the other hand username is shown straight because the input type in username is text:

<p>Enter Username:

<input type=”text” name=”user”/>

</p>

 

Providing the form with right username and password will take you to the page lamp1.php due to the action of the tag:

<form method=”post” action=”lamp1.php”>

In higher levels the authentication is done through matching the information through a MySQL database.

 

 

 


Leave a Reply