2010-02-22 25 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)); 
}