Page 1 of 1

how to write a php statement within a textbox

Posted: Wed Oct 08, 2008 12:42 am
by swetha
i have the following code for a textarea,in which i have written php code;

Code: Select all

 
textarea name="normaltxt" width="100" height="100" readonly="readonly">
<?php if (isset($_POST['submit'])){echo $pwd;} else {echo " ";} ?>
</textarea>
 
the above code i need to convert to a textbox

Code: Select all

 
<input type="text" name="textname" height="20" maxlength="25" 
<?php if (isset($_POST['submit'])) {"value=$pwd";}?>
 
but the output is not getting printed in the textbox.

i need to print the password output to a textbox instead of textarea.is it right to put the coding within the value tag?

Re: how to write a php statement within a textbox

Posted: Wed Oct 08, 2008 3:04 am
by papa
Try:

Code: Select all

<?php if (isset($_POST['submit'])) { echo "value=$pwd";}?>

Re: how to write a php statement within a textbox

Posted: Wed Oct 08, 2008 3:05 am
by mchaggis
Your problem is that when you print "value=$pwd" the reult would be value=abc123 and should be value="abc123"

Try:

Code: Select all

 
<input type="text" name="textname" height="20" maxlength="25"
value="<?php if (isset($_POST['submit'])) { print $pwd; }?>"
/>
 
Alternatively, you could use php short hand:

Code: Select all

 
<input type="text" name="textname" height="20" maxlength="25"
value="<?=(isset($_POST['submit']))?$pwd:''?>"
/>
 

Re: how to write a php statement within a textbox

Posted: Wed Oct 08, 2008 5:53 am
by swetha
thanks the following worked

Code: Select all

 
<?php if (isset($_POST['submit'])) { echo "value=$pwd";}?>