2014-01-17 20 views
0

我有這樣的代碼來獲取文件中的信息並顯示結果。這一切都按預期工作。我無法做的是在按下按鈕時將按鈕的值導出,這樣按下按鈕的值就會轉移到我的php函數中的一個變量中。我怎樣才能做到這一點?在php函數中導入html值

下面的代碼:

<h2>Demmarage script torrent</h2> 
<form action="search.php" method="POST"> 
<input type="text" name="input_value"> 
<input type="submit" name="submit"> 
<?php 
echo "<br>"; 
if (isset($_POST['submit'])){ 
    $findme = $_POST['input_value']; 
    $findme1 = str_replace (" ", ".", $findme); 
    $savedarr = unserialize(file_get_contents('torrent.bin')); 

    foreach ($savedarr as $val1){ 
     $mystring = $val1['title']; 
     if((stripos($mystring, $findme) !== false) or (stripos($mystring, $findme1) !== false)) { 
      echo "Show trouve: "; 
      echo $mystring; 
      ?> 

      <button type="submit" value="<?php echo $val1['link']; ?>" name="editId">Telecharger</button> 

      <?php 
      echo "<br>"; 
     } 
    } 
} 
if (isset($_POST['editId'])){ 
    //Here i want to import the value of the pressed button to do something 
    echo "download start"; 
} 
?> 

回答

0

你應該使用隱藏域,像

<input type="hidden" name="link" id="link" value="<?php echo $val1['link'] ?>" /> 

提交後,您將能夠與

$_POST['link'] 

而且得到的價值,這應該是一種形式,否則提交將發佈每個字段...

foreach(...) 
{?> 
    <form action="" method="POST"> 
    <input type="hidden" name="link" id="link" value="<?php echo $val1['link'] ?>" /> 
    <input type="submit" /> 
    </form> 
<?php} 
+0

感謝就是這樣,它的工作。再次感謝。 – user3199862

0

的問題是,你被<button>value1</button><button value="value2">兩次將該值設置......請記住,一個提交按鈕的值始終是按鈕內顯示的文本。

你應該做替換此:

<button type="submit" value="<?php echo $val1['link']; ?>" name="editId">Telecharger</button> 

本:

<form method="POST"> 
    <input type="hidden" value="<?=$val1['link']?>" name="editId" /> 
    <input type="submit" value="Telecharger" /> 
</form>