HTML/PHP - default input value

前端 未结 10 1338
梦如初夏
梦如初夏 2020-12-11 16:48

I have a post php form and a set of inputs:

  1. Your Name
  2. Your Last Name
  3. My Name

Every input looks the same, only the names change

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 17:33

    You could use my tiny library ValueResolver in this case, for example:

    $default = ValueResolver::resolve(get_option('your_name'), '');
    

    and don't forget to use namespace use LapaLabs\ValueResolver\Resolver\ValueResolver;

    There are also ability to typecasting, for example if your variable's value should be integer, so use this:

    $id = ValueResolver::toInteger('6 apples', 1); // returns 6
    $id = ValueResolver::toInteger('There are no apples', 1); // returns 1 (used default value)
    

    Check the docs for more examples

提交回复
热议问题