VelvetMirror Posted March 26, 2011 Share Posted March 26, 2011 First way: <?php$name = "Introduce your name";echo " <form action='index.php'> <input type='text' id='name' value='$name' /> </form>";?> Second way: <?php$name = "Introduce your name";echo "<form action='index.php'>";echo "<input type='text' id='name' value='$name' />";echo "</form>";?> Third way: <form action='index.php'> <input type='text' id='name' value='$name' /></form> This last one wouldn't work since the $name variable isn't between php tags so it wouldn't be recognized. Obviously I could just type the variable value between the single quotes and it would work fine, but I want to use a variable, because if it was a $_GET variable for example, I couldn't do that, since I wouldn't know it's value beforehand. I don't like much the first two because eliminates the autoformat and highlighting of the code (I use netbeans)Any better alternative? Link to comment Share on other sites More sharing options...
shadowayex Posted March 26, 2011 Share Posted March 26, 2011 You could heredoc: echo <<< FORM<form action='index.php'> <input type='text' id='name' value='$name' /></form>FORM; Or you could just put in the PHP tags: <form action='index.php'> <input type='text' id='name' value='<?php echo $name; ?>' /></form> Link to comment Share on other sites More sharing options...
birbal Posted March 26, 2011 Share Posted March 26, 2011 it will be something like <form action='index.php'> <input type='text' id='name' value='<?php echo $name; ?>' /></form> <?php ?> inside this block php will parse the code. which will evaluate the value of $name Link to comment Share on other sites More sharing options...
VelvetMirror Posted March 26, 2011 Author Share Posted March 26, 2011 Thanks, that's much better. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.