how to write a php statement within a textbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

how to write a php statement within a textbox

Post 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?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: how to write a php statement within a textbox

Post by papa »

Try:

Code: Select all

<?php if (isset($_POST['submit'])) { echo "value=$pwd";}?>
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Re: how to write a php statement within a textbox

Post 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:''?>"
/>
 
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

Re: how to write a php statement within a textbox

Post by swetha »

thanks the following worked

Code: Select all

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