簡體   English   中英

如何從表單獲取用戶輸入?

[英]How do I get user input from a form?

我有當前的PHP:

$thisarray[] = "#000";

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

usercss #000寫入標記為usercss的用戶配置文件字段。

但是, 我希望用戶能夠通過簡單的形式設置值。

誰能建議我可能使用的一些代碼?

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

來自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));
}

如果您不了解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));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM