2010-02-22 23 views
0

我目前的PHP:如何從表單獲取用戶輸入?

$thisarray[] = "#000"; 

SetProfileField('usercss', $USER->id, implode(',',$thisarray)); 

後者寫到#000到配置文件字段標usercss用戶。

但是我希望用戶能夠從簡單的表單設置值。

任何人都可以提出一些我可能會用到的代碼嗎?

++希望將此擴展爲包含jQuery顏色選擇器,以便用戶不需要知道十六進制。例如。 http://acko.net/dev/farbtastic

回答

0

從例如在http://acko.net/dev/farbtastic

<form action="yourFile.php" method="post"> 
    <div style="margin-bottom: 1em;" id="picker"> 
    <div class="farbtastic"> 
     <div class="color" style="background-color: rgb(0, 127, 255);"></div> 
     <div class="wheel"></div> 
     <div class="overlay"></div> 
     <div class="h-marker marker" style="left: 55px; top: 170px;"></div> 
     <div class="sl-marker marker" style="left: 82px; top: 127px;"></div> 
    </div> 
    </div> 
    <div class="form-item"> 
    <label for="color">Color:</label> 
    <input type="text" style="width: 195px; background-color: rgb(18, 52, 86); color: rgb(255, 255, 255);" value="#123456" name="color" id="color"> 
    </div> 
</form> 

和你的PHP:

if (!empty($_POST['color']) && preg_match('/^#[a-fA-f0-9]{6}/', $_POST['color']) != 0) { 
    $thisarray[] = $_POST['color']; 
    SetProfileField('usercss', $USER->id, implode(',',$thisarray)); 
} 
+0

-1:非過濾用戶輸入 – hobodave 2010-02-22 20:16:19

+0

你正確..編輯我的答案 – harpax 2010-02-22 20:31:48

0

如果你不知道PHP,我建議閱讀一些教程。

如果你這樣做,那麼下面應該設置你在正確的道路上:

HTML:

<input name="usercss" value="" type="text" /> 

PHP:

if (isset($_POST['usercss'])) { 
    $usercss = filterUserInputPlease($_POST['usercss']); 
    $thisarray[] = $usercss; 
    SetProfileField('usercss', $USER->id, implode(',',$thisarray)); 
}