0

I have following code:

<html>
<head>
<meta charset="UTF-8"/>
</head>
<body>

<!--See siin all tekstiväli--> 
<H3>Minu küsitlused </H3>
<hr>
<br>
<br>
<br>

<ol>
<?php
include_once 'init/init.funcs.php';
$result = mysql_query('SELECT * from katse_kysimustik_pealkiri');
while($row = mysql_fetch_assoc($result)) {
        $titles[] = $row['pealkiri'];
        }
foreach($titles as $title) {?>
    <li>
    <?php echo $title ?>
<form action='Minu_kysitlused_1.php' method="post">
    <input type="submit" name = "saada" value="saada"/>
    <input type="button" value="tulemused"/>
    <input type="button" value="lõpeta ennetähtaegselt"/>
    <input type="button" value="X"/>
    </li>
</form>
<?php
}
?>
</ol>


</body>
</html>

<?php
if(isset($_POST['saada'])){
header("Location:http://localhost/Praks/saada.html");
}

?>

Right now there is button "saada" for each title in database. When I click "saada", page saada.html will appear.

This is saada.html

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8"/>
    <title>Saada</title>
  </head>
  <form action="test1.php" method="POST">
  <body>
    <header>Küsitluse pealkiri</header>
    <br>
    Lisa sõnumile pealkiri:
    <br>
    <textarea rows='1' name='pealkiri'>Küsitluse algne pealkiri</textarea>
      <br>
      Lisa Adressaadid: <br>
    <textarea rows='1' name='email'></textarea>
   <br>
   Lisa sõnum:
   <br>
    <textarea rows='4' name='tekst'></textarea>

    <br><footer>


    <INPUT TYPE="submit" VALUE="Saada" NAME="Saada">
    </form>

    <FORM METHOD="LINK" ACTION="Minu_kysitlused.html">
    <INPUT TYPE="submit" VALUE="Loobu">


    </footer> 
  </body>
</html>

My question is how could I make it work so value of $title appears in saada.html. The value of this $title which is next to 'saada' button I clicked. I need this value to be in this line instead of Küsitluse algne pealkiri:

<textarea rows='1' name='pealkiri'>Küsitluse algne pealkiri</textarea>
Jenz
  • 8,280
  • 7
  • 44
  • 77
user244902
  • 143
  • 4
  • 14

1 Answers1

1

You can not have a value through PHP in HTML type page....change page extension to .php

then pass your $title in input hidden field in your form

like this

foreach($titles as $title) {?>
    <li>
    <?php echo $title ?>
<form action='Minu_kysitlused_1.php' method="post">
    <input type="submit" name = "saada" value="saada"/>
    <input type="button" value="tulemused"/>
    <input type="button" value="lõpeta ennetähtaegselt"/>
    <input type="button" value="X"/>
    <input type="hidden" name="title" value="<?php echo $title;?>"/> 
    </li>
</form>
<?php
}
?>

Now set the cookie

<?php
if(isset($_POST['saada']))
{
 if(isset($_REQUEST['title']))
 { 
   $title = $_REQUEST['title'];
   setcookie("page_title", $title, time()+3600); 
 }
 header("Location:http://localhost/Praks/saada.html");
}

?>

Now on Your saada.html you can use js to retrieve cookie like this

JS Function Reference

var title = getCookie("page_title"); // retrieve cookie

document.getElementById('page_title').value = title; // put title into textaread


function getCookie(name) {
  var value = "; " + document.cookie;
  var parts = value.split("; " + name + "=");
  if (parts.length == 2) return parts.pop().split(";").shift();
}

<textarea rows='1' name='pealkiri' id="page_title" >Küsitluse algne pealkiri</textarea>
Community
  • 1
  • 1
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51