How to assign HTML textbox value into PHP variable and vice versa on same page.

searchsanjaysharma
searchsanjaysharma used Ask the Experts™
on
1. How to assign HTML Textbox value into a PHP variable through Function.
2. How to assign PHP variable into HTML variable.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
A HTML textbox could be either a <INPUT TYPE="text"> or a <TEXTAREA>.
They usually get a name assigned:

<INPUT TYPE="text" NAME="textfield1">

They are usually part of a form, that, when submitted sends its form data to the script defined in the action attribute:

<FORM ACTION="/mysite/script.php" METHOD="POST">

The method will decide on how the variable will be transferred and how you can access it from PHP.

Posting will give all the form data as part of the $_POST array.
Using the GET method will make you use the $_GET array.

If you use the example above, the contents of the text box will be available by reading the variable $_POST['textfield1'].
can you please elaborate the question...from what i understand...you need to know how to send data in an html textarea into a php script, and then change the content in the textarea to what the php script would return? or are the two tasks unrelated?
1- assign HTML textbox to PHP variable.
<html><head><title>example1</title></head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" size="15" name="var1" />
<input type="submit" value="assign" />
</form></body>
</html>

<?php
$var =$_POST["var1"];
// now you can do wtf you want with the variable.
?>
2-HTML doesn't have is not a programming language so it does have variables
you may use javascript - vbscript.
<?php
$country="egypt";
?>
<?php
echo "<script type="/text/JavaScript"/> ";
echo "var my_var = $country" ;
echo "</script>";
?>

Regards.
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

sorry for the typo
2- HTML doesn't have variables you may use Javascript or vbscript.
Regards.

Author

Commented:
I means to say the value is to be assigned to HTML textbox, it is self understood.
here's the answer to your number 2.

<textarea name="whatever"><?php echo $text;?></textarea>

just put whatever you want to appear inside the textarea within the tags.

Author

Commented:
ok

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial