简体   繁体   中英

How do I get user input from a form?

I have the current PHP:

$thisarray[] = "#000";

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

Which writes #000 to the users profile field labelled usercss .

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

Can anyone suggest some code I might use?

++ Hope to extend this to include a jQuery color picker so the user does not need to know the hex. Eg http://acko.net/dev/farbtastic

from the example on 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>

and your php:

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

If you don't know PHP I suggest reading some tutorials.

If you do, then the following should set you on the right path:

HTML:

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

PHP:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM