Nasıl bir formda kullanıcı girişi alabilirim?

2 Cevap php

Ben mevcut PHP var:

$thisarray[] = "#000";

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

#000 etiketli kullanıcı profil alanına usercss hangi yazar.

Ancak I would like the user to be able to set the value from a simple form.

Herkes kullanabilir bazı kod önerebilirsiniz?

++ kullanıcı onaltılık bilmeniz gerekmez böylece bir jQuery renk seçici eklemek için bu uzatmak dileğiyle. Örneğin http://acko.net/dev/farbtastic

2 Cevap

Örnek itibaren 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>

ve 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 bilmiyorsanız ben bazı dersler okumanızı öneririz.

Bunu yaparsanız, o zaman şu doğru yolda ayarlamanız gerekir:

HTML:

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

PHP:

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