douzheyo2617 2016-02-09 18:51
浏览 32
已采纳

first_name,lastname和job title的日期条目应采用驼峰格式,即使用户输入所有大写字母也是如此

So this is my code for the first_name. I have no clue why it does not work whenever I add an entry.

First Name: <input type="text" name="first_name" value="<?php function convertString($first_name){
$first_name=htmlentities(strip_tags($first_name));
$lowercaseFName = strtolower($first_name);
$ucFName = ucwords($lowercaseFName);
return $ucFName;} ?>"/> // I changed it with echo but nothing changed.

My code doesn't change the format of the text.I tried inputting in all caps and it will show as is. Am I missing something or doing it wrong?

The inputted text if all in capital must still be shown as Camel Case format in the table, like this:

First Name: MARIA YLONA (in the form)

First Name: Maria Ylona (in the table) - this is another .php file for viewing of the data entries

  • 写回答

2条回答 默认 最新

  • doukezi4576 2016-02-09 19:26
    关注

    Seeing you didn't post your html form or how it's used, am submitting the following as a successful piece of code and using !empty() against a POST array with form tags and an isset() for the submit input.

    Btw, functions and variables assignments should be used seperately than in inputs/form elements.

    Create a function, then pass it inside the input with the parameter.

    <?php
    function convertString($first_name){
      $first_name=htmlentities(strip_tags($first_name));
      $lowercaseFName = strtolower($first_name);
      $ucFName = ucwords($lowercaseFName);
      return $ucFName;
    }
    
    
    if(isset($_POST['submit'])){
    
        if(!empty($_POST['first_name'])){
    
           $first_name = $_POST['first_name'];
    
        }
    
    }
    
    // here initialize $first_name to something meaningful
    ?>
    
    <form method="post">
    First Name: <input type="text" name="first_name" value="<?php echo(convertString($first_name)) ?>"/>
    
    <input type="submit" name="submit" value="Submit">
    
    </form>
    

    Footnotes:

    In regards to what Marc mentioned about McDonald's -> mcdonald's -> Mcdonald's and my MacDonald in comments...

    Consult the following here on Stack which may prove to be useful:

    You mention the use of a database, but haven't posted relative code and would be beyond the scope of the question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。