Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping non-sensible info into a formulary

Status
Not open for further replies.

kyru

Programmer
Jan 17, 2009
45
ES
Let's suppose I have an application with several formularies, before submitting the formulary the user can check what he has introduced, all non-sensible information in those formularies that was given before by the user must be filled automatically. I've tried doing it this way:

<?php
if ($_POST['enviar'])
{
echo (nl2br("Button pressed\n"));
echo(nl2br("The content of texto is ".$_POST['texto']."\n"));
print '<a href=otro.php>Return to form</a>';

}
else {
$temp=$_POST['texto'];
print '<form action="otro.php" method="post">
<input type="submit" name="enviar">
<input type="text" name="texto" value="$temp">
<input type="text" name="texto2">';
}
?>

So the field text would take the value $_POST['texto'] always the form gets an instance, but the html page prints $temp literally in the textbox instead, sigh.

I'm not too sure if the $_POST['texto'] keeps the info after pressing the link to go back to the form. So, I'd better just put the form info into a temp file and get the info from that file later. Anyway how I'm supposed to tell the html page that it takes that value by default?

Thanks in advance.
 
You have this block in a single quote, which won't interpolate.

Code:
print '<form action="otro.php" method="post">
      <input type="submit" name="enviar">
      <input type="text" name="texto" value="$temp">
      <input type="text" name="texto2">';

Fix by doing:

Code:
print '<form action="otro.php" method="post">
      <input type="submit" name="enviar">
      <input type="text" name="texto" value="' . $temp . '">
      <input type="text" name="texto2">';

Scott Prelewicz
Web Developer
COMAND Solutions
 
Thanks, it works great now, it's necessary to use a temp file anyway.
 
rather than single quote breakout you might consider using heredoc instead. it is a bit slower to parse but much easier to use for html blocks

Code:
echo <<<HTML
      <form action="otro.php" method="post">
      <input type="submit" name="enviar">
      <input type="text" name="texto" value="$temp">
      <input type="text" name="texto2">
HTML;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top