2015-04-27 45 views
1

我有一個Raspberry Pi 2 B 與我控制我的led燈帶的GPIO引腳。 我在PHP中做了一些東西。 按鈕工作正常,但我不知道如何獲得輸入文本框字符串。PHP命令+值?怎麼樣?

這是我的腳本:

<?php 

if (isset($_POST['button11'])) { 
    exec('pigs p 18' + INPUT TEXTBOX OR JSCOLOR RED OUTPUT); 
    exec('pigs p 23' + INPUT TEXTBOX OR JSCOLOR GRN OUTPUT); 
    exec('pigs p 24' + INPUT TEXTBOX OR JSCOLOR BLU OUTPUT); 
} 

?> 
<html> 
    <head> 
    <script type="text/javascript" src="jscolor/jscolor.js"></script> 
<form name="form" action="" method="get"> 
    <input name="red" id="red" size="5"> 
    <input name="grn" id="grn" size="5"> 
    <input name="blu" id="blu" size="5"> 
</form> 
<p> Of kies een kleur: <input class="color" id="myColor" onchange=" 
    document.getElementById('red').value = this.color.rgb[0]*255; 
    document.getElementById('grn').value = this.color.rgb[1]*255; 
    document.getElementById('blu').value = this.color.rgb[2]*255; 
    <title>Sherin's RGB Ledstrip</title> 
    </head> 
    <form method="post"> 
    <p> 
     <button name="button11" style="background-color:#000000; color: #ffffff;" > 
      Activeer je bovenstaande gekozen kleur 
     </button> 
    </p> 
    </form> 

我知道INPUT TEXTBOX不會工作。但我如何獲得該文本框的值並將其粘貼到命令後? 我使用了顏色選擇器,名稱:JSCOLOR。 我想要3個命令後的R字符串,G字符串,B字符串。

請幫

感謝

+0

將您的紅色,藍色和綠色字段移動到第二個表單內。然後,在提交之後,你可以使用'$ _POST ['red'],$ _POST ['blue'],...'來訪問它們。' –

+0

另外,你可以考慮使用[escapeshellarg函數](http:///php.net/manual/en/function.escapeshellarg.php)安全地使用用戶輸入與您的命令呼叫。 –

回答

0

你必須創建一個適當的形式。

<?php 

if (isset($_POST['form'])) { 
    $form = $_POST['form']; 

    if ($form == 'my_form') { 
     $input = $_POST['my_value']; // read the value from the textbox 
    } 
} 

?> 

<form method="post"> 
    <input type="text" name="my_value" value="foo" /> 
    <input type="hidden" name="form" value="my_form" /> 
    <input type="submit" /> 
</form> 
0

您需要將這些:

<input name="red" id="red" size="5"> 
<input name="grn" id="grn" size="5"> 
<input name="blu" id="blu" size="5"> 

下到與它的按鈕形式。這樣他們的值將在POST變量中。

坦率地說,它很難準確地告訴你需要根據你的代碼結構提交什麼值。請記住,您希望通過表單提交的任何投入都需要位於表單的代碼中(而不是其他表單或其他表單)