how to access textarea in php ??
Moderator: General Moderators
how to access textarea in php ??
hi guys
I have a form in which when a user doesnt enter any required field an alert message pop ups and when the user clicks on the OK button it goes back to the form and empties the textarea fields while the text fields remains unchanged...
is there any value attribute for textarea?
ple reply and help me
thnx in advance
Jack
I have a form in which when a user doesnt enter any required field an alert message pop ups and when the user clicks on the OK button it goes back to the form and empties the textarea fields while the text fields remains unchanged...
is there any value attribute for textarea?
ple reply and help me
thnx in advance
Jack
Something like
Code: Select all
<?php
$html['message'] = htmlentities($_POST['message'],ENT_QUOTES, 'UTF-8');
?>
<textarea name="message" id="message" cols="40" rows="6"><?php echo (isset($_POST['message'])) ? $html['message'] : ""; ?></textarea>I didnt get youmatthijs wrote:Something likeCode: Select all
<?php $html['message'] = htmlentities($_POST['message'],ENT_QUOTES, 'UTF-8'); ?> <textarea name="message" id="message" cols="40" rows="6"><?php echo (isset($_POST['message'])) ? $html['message'] : ""; ?></textarea>
this is my code
<textarea rows="3" name="Address" cols="43" style="border-style: solid; border-width: 1px"></textarea></td></tr>
how to edit it??
plz reply
Code: Select all
<html>
<head>
<title></title>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
// do some text field validatioin
if($_POST['textarea1']=="")
{
$text_val=$_POST['text1'];
echo "<script language='javascript'> alert('textarea cannot be empty');</script>\n";
$texta_value="";
}
else
{
//YOU CAN TAKE ANY ACTION HERE
}
}
else
{
$text_val="";
$texta_value="";
}
?>
<form name='f1' method=post action='samepage.php'>
<input type='text' name='text1' value=<?php echo $text_val;?>>
<textarea name='textarea1' col5=2 rows=5 value=<?php echo $texta_value; ?>></textarea>
<input type='submit' name='submit' value='submit'>
</form>
</body>
</html>- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
I disagree. In php, especially if you are accessing a database you never trust user input and should always validate data, even if validation is also done using javascript. Even with simple tools (like firefox webdeveloper) javascript validation can be bypassed and potentially harmful data inserted.Ind007 wrote:but it is hardway of doing validation using php, you can make use of javascript to do this as time is the factor
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Never rely on client side technology for security or validation. A user can easily turn off JavaScripting and then your validation is caput.
Yes and no... the value you want for the text area goes between the <textarea> and </textarea> tags, as matthijs explained in his post. But there is not value attribute for textarea as you would have like in the <input> elements.jack001 wrote:is there any value attribute for textarea?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
htmlentities()/htmlspecialchars() is pretty much required for all form field values, including text areas.
As for using Javascript to pass the text in a textarea to the value of the same textarea does nothing but set the text. You would need to use Ajax to send the information to PHP if you didn't want to refresh the page. At any rate, that's just a waste of time most likely. In fact sending the contents of the text area every key press would be a horrific CPU and bandwidth eater.
As for using Javascript to pass the text in a textarea to the value of the same textarea does nothing but set the text. You would need to use Ajax to send the information to PHP if you didn't want to refresh the page. At any rate, that's just a waste of time most likely. In fact sending the contents of the text area every key press would be a horrific CPU and bandwidth eater.
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
No Ididn't Meant That
I Mean On KEYPRESS On the TEXTAREA The value of that TEXTAREA Will be = innerTEXT Of That textarea So The Textarea Will Have The Same Text In its Value
Ore In The Value of Any Other hidden Fields Value Attributes
And For This purpouse AJAX Is Not Required
Cause Its Not Semding The Data To The Server Its Sharing The Data In Client Side
Between two Attributes php Will Parse Its value Attribute Just Like An input Element
EDITED
I Mean On KEYPRESS On the TEXTAREA The value of that TEXTAREA Will be = innerTEXT Of That textarea So The Textarea Will Have The Same Text In its Value
Ore In The Value of Any Other hidden Fields Value Attributes
And For This purpouse AJAX Is Not Required
Cause Its Not Semding The Data To The Server Its Sharing The Data In Client Side
Between two Attributes php Will Parse Its value Attribute Just Like An input Element
EDITED
Last edited by neel_basu on Tue Dec 12, 2006 11:50 pm, edited 1 time in total.
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Well This Function Will Pass The Text To Value
================================
And here Is A Compleate Example
========================
php Will Parse The Form Filed (hid_hld) not The Textarea
If You Don't Want To Display The hid_hld Textbox You Can Make It Hidden
================================
Code: Select all
function pass_val(ev)
{
var hld_txt = document.getElementById("tst").innerHTML;
document.getElementById("hid_hld").value = hld_txt;
}Code: Select all
<form name="frm">
<textarea name="tst" rows="2" name="S1" cols="20" id="tst" onKeyUp="pass_val(event);"></textarea>
<br />
<input type="text" name="nm_hid_hld" size="20" id="hid_hld">
</form>========================
Code: Select all
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Pass_TextArea_Text</title>
<script>
function pass_val(ev)
{
var hld_txt = document.getElementById("tst").innerHTML;
document.getElementById("hid_hld").value = hld_txt;
}
</script>
</head>
<body>
<form name="frm">
<textarea name="tst" rows="2" name="S1" cols="20" id="tst" onKeyUp="pass_val(event);"></textarea>
<br />
<input type="text" name="nm_hid_hld" size="20" id="hid_hld">
</form>
</body>
</html>Code: Select all
$_POST[hid_hld]Code: Select all
<input type="hidden" name="nm_hid_hld" size="20" id="hid_hld">neel_basu wrote:Well This Function Will Pass The Text To Value
================================Code: Select all
function pass_val(ev) { var hld_txt = document.getElementById("tst").innerHTML; document.getElementById("hid_hld").value = hld_txt; }And here Is A Compleate ExampleCode: Select all
<form name="frm"> <textarea name="tst" rows="2" name="S1" cols="20" id="tst" onKeyUp="pass_val(event);"></textarea> <br /> <input type="text" name="nm_hid_hld" size="20" id="hid_hld"> </form>
========================php Will Parse The Form Filed (hid_hld) not The TextareaCode: Select all
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Pass_TextArea_Text</title> <script> function pass_val(ev) { var hld_txt = document.getElementById("tst").innerHTML; document.getElementById("hid_hld").value = hld_txt; } </script> </head> <body> <form name="frm"> <textarea name="tst" rows="2" name="S1" cols="20" id="tst" onKeyUp="pass_val(event);"></textarea> <br /> <input type="text" name="nm_hid_hld" size="20" id="hid_hld"> </form> </body> </html>If You Don't Want To Display The hid_hld Textbox You Can Make It HiddenCode: Select all
$_POST[hid_hld]Code: Select all
<input type="hidden" name="nm_hid_hld" size="20" id="hid_hld">
hi neel
can u adjust this in my php form???
plz dear
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: how to access textarea in php ??
Why are you emptying the textarea and leaving all the others unchanged? And what happens when javascript is disabled? Why not let the server handle this?jack001 wrote:I have a form in which when a user doesnt enter any required field an alert message pop ups and when the user clicks on the OK button it goes back to the form and empties the textarea fields while the text fields remains unchanged...
If this thread doesn't start to actually be about PHP Code I am going to move it to Client Side soon.