douchang8219 2014-02-10 20:47
浏览 130

输入字符串以下划线的形式分隔

I haven't come to much luck finding anything on this, since I couldn't think how to word it originally.

Basically I have a form, in HTML, the end user will submit a value such as "12345_54321" into 1 input field, then process.

I would like to be able to allow there to be 2 input fields instead, so one of them they would enter "12345" and in the second one, they'd enter "54321".

Which seems easy enough, but my real need is that the "_" must be used as a separator, such as, when the value is submitted, it will process "12345_54321" instead of "12345" and "54321"

My form so far:

<form role="form" method="post" action="process.php">
<fieldset>
<div class="form-group">
  <input size="18" type="visible" name="postid" id="postid" class="form-control" placeholder="Enter Story ID Here:" class="input-medium" ><input size="18" type="visible" name="postid" id="postid" class="form-control" placeholder="Enter Comment ID Here:" class="input-medium" >
</div>
    <input type="submit" name="submit" class="btn btn-primary btn-large" id="submit_btn" value="Process"/>
</fieldset>

  • 写回答

2条回答 默认 最新

  • duanke0555 2014-02-10 20:54
    关注

    If you want to display 2 inputs for the story id, you have to modify your page to be like so (no need for the underscore (_):

    <form role="form" method="post" action="process.php">
      <fieldset>
        <div class="form-group">
          <input size="18" type="visible" name="story_id_1" id="story_id_1" class="form-control" placeholder="Enter Story ID Here:" class="input-medium" >
          <input size="18" type="visible" name="story_id_2" id="story_id_2" class="form-control" placeholder="Enter Story ID Here:" class="input-medium" >
          <input size="18" type="visible" name="comment_id" id="comment_1" class="form-control" placeholder="Enter Comment ID Here:" class="input-medium" >
        </div>
        <input type="submit" name="submit" class="btn btn-primary btn-large" id="submit_btn" value="Process"/>
      </fieldset>
    </form>
    

    In your process.php you can get these variables by looking in your POST.

    <?php
    $story_id_1 = '';
    $story_id_2 = '';
    $comment_id = '';
    
    // Check for empty fields
    if(isset($_POST['story_id_1']))
      $story_id_1 = $_POST['story_id_1']; // From HTML Page
    if(isset($_POST['story_id_2']))
      $story_id_2 = $_POST['story_id_2']; // From HTML Page
    if(isset($_POST['comment_id']))
      $comment_id = $_POST['comment_id']; // From HTML Page
    
    print 'Story Id 1: '. $story_id_1 . '</br>';
    print 'Story Id 2: '. $story_id_1 . '</br>';
    print 'Comment Id: '. $comment_id . '</br>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?