Vai all'homepage Area Webmaster Area Computer Un pò di tutto...  
Web Tutorial > Form components

Form components

In this article I address a subject that I find very interesting because applications often require the modules, the so-called form.
Contains a form that can be compoennti:
- Text input (text field)
- Text boxes (text area)
- Option Button
- Check Box

Now we will see how it is aa possiible using php to read the selected data using these components of a form.

Building the form with components

As a first step we construct a form containing all the components listed above. Inseriamoil test.htm form on the page.

<form id="form_tutorial" name="form_tutorial" method="post" action="z_read.php">
<label>input text
<input name="input_text" type="text" id="input_text" value="input text content" />
</label>
<p>
<label>text area
<textarea name="text_area" id="text_area" cols="45" rows="5">text area content</textarea>
</label>
</p>
<p>
<label>
<input name="check_box" type="checkbox" id="check_box" checked="checked" value="check-box on" />
check-box</label>
</p>
<p>
<label>
<input type="radio" name="radio_button" id="radio_button" value="radio-button on" />
radio button</label>
</p>
<p>
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</p>
</form>

If you want to see a preview click here

Reading the values of the components

Now let's build the page read.php that we must read the values ​​set through the components of the form:

<?php
$input_text = $_POST['input_text'];
$text_area = $_POST['text_area'];
$check_box = "check box off";
if (isset($_POST['check_box']))
{$check_box = $_POST['check_box'];}
$radio_button = "radio button off";
if (isset($_POST['radio_button']))
{$radio_button = $_POST['radio_button'];}
echo $input_text."<br>".$text_area."<br>".$check_box."<br>".
$radio_button;
?>

As we can see, while the input-text and text-area it was possible to read the value without controls, the check-box and radio button was not necessary to initialize the variable associated with a value (in our case "off") then it was necessary to verify the existence through isset instruction. If it is not ticked the checkbox and radio button, the associated variables are not created.

 
Homepege
Who I am
Web Tutorial
Script php
Computer
Chat
Contacts
Links
Phone organizer
CSS Menu
Form components
Php and cookies
Php redirect
Pretty Guestbook 2.0
Web Shoutbox
...All
Form components
Php and cookies
Php redirect
Time loading page
Random characters
Words detecting
Php and functions
...All
Phone organizer
Ascii code
...All

Privacy terms Google Ads | Website realized by Morris
Free counter