Website Development Prices

Search Blog

Friday, June 10, 2016

Preuzimanje podataka iz oblasti za unos teksta (Retrieving data from textareas)

Oblasti za unos teksta su kontrole u kojima korisnik moze da unese vise redova teksta. Pravi se pomocu elementa <textarea>.

Primer: trazicemo od korisnika da navede svoje omiljene motore. To se unosi u oblasti za unos teksta sa imenom "motori". Kada korisnik klikne dugme Posaljite, podaci ce se poslati do PHP skripta php-oblast-teksta.php i ti podaci ce se prikazati na novoj web stranici. Podatke cemo preuzeti uz pomoc niza $_POST["motori"].

HTML kod

<!DOCTYPE html>
<html>
<head>
<title>HTML forme</title>
</head>


<body>
<h1>Upotreba oblasti za unos teksta</h1>

<form method="post" action="php-oblast-teksta.php">
<h3>Koji su vasi omiljeni motori?</h3>
<br />
<textarea name="motori" cols="30" rows="3">

</textarea>
<br /><br />
<input type="submit" value="Posaljite">
</form>
</body>

</html>

Sacuvajte ovaj fajl kao php-oblast-teksta.html, u folderu htdocs, foldera xampp. U mom primeru, putanja je C:/xampp2/htdocs/PHPtuts/oblasti-za-unos-teksta/php-oblast-teksta.html.

PHP kod

<!DOCTYPE html>
<html>
<head>
<title>HTML forme</title>
</head>

<body>
<h1>Preuzimanje podataka iz oblasti za unos teksta</h1>

Vasi omiljeni motori su

<?php
echo $_POST["motori"];
?>

</body>

</html>

Sacuvajte ovaj fajl kao php-oblast-teksta.php u istom folderu kao i php-oblast-teksta.html.

Rezultat:




Textareas are controls in which the user can enter multiple rows of text. It is made by element <textarea>.

Example: we will ask the user to specify their favorite motorcycles. It is entered in the textarea with the name "motorcycles". When the user clicks the Send button, the data will be sent to the PHP script php-textarea.php and this data will be displayed on the new web page. We will retrieve data with the help of array $_ POST["motorcycles"].

HTML code

<!DOCTYPE html>
<html>
<head>
<title>HTML forms</title>
</head>

<body>
<h1>Using textarea</h1>

<form method="post" action="php-textarea.php">
<h3>What are your favorite motorcycles?</h3>
<br />
<textarea name="motorcycles" cols="30" rows="3">

</textarea>
<br /><br />
<input type="submit" value="Send">
</form>
</body>

</html>

Save this file as php-textarea.html, in the htdocs folder, of the folder xampp. In my example, the path is C: /xampp2/htdocs/PHPtuts/textarea/php-textarea.html.

PHP code

<!DOCTYPE html>
<html>
<head>
<title>HTML forms</title>
</head>

<body>
<h1>Retrieving data from textareas</h1>

Your favorite motorcycles are

<?php
echo $_POST["motorcycles"];
?>

</body>

</html>

Save this file as php-textarea.php in the same folder as the php-textarea.html.

Result:





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.