抓取URL字符串的末尾并将其插入到表单字段中

时间:2018-08-10 16:18:40

标签: javascript php forms parsing

我的网站上有嵌入式表格。我试图在最后一个正斜杠之后获取URL的末尾,然后将其填充在表单字段中。 URL的末尾将有多个实例,我需要将其打印在后端,以便将其与表单中输入的其他信息进行匹配。我试过了,但是没用:

Cannot fit requested classes in a single dex file. Try supplying a main-dex 
list.
# methods: 71967 > 65536
Message{kind=ERROR, text=Cannot fit requested classes in a single dex file. 
Try supplying a main-dex list.
# methods: 71967 > 65536, sources=[Unknown source file], tool 
name=Optional.of(D8)}

form_230f1916-6f5f-460d-a6d9-5d2233010684是我要填写的表单字段的ID。我是脚本新手,所以将不胜感激。

2 个答案:

答案 0 :(得分:0)

var urlSplit = url.split("/");
var lastString = urlSplit[urlSplit.length - 1];

答案 1 :(得分:0)

您还需要更新jquery .val()函数。这是另一种方法。

<?php
//set the URL you want to parse
$url = "http://umoem.stage3.commercialprogression.net/hail/jsharer0001";
//convert it into an array
$segments = explode("/",$url);
//get the last segment of the array
$lastSegment = end($segments);

 ?>
<script
  src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
  integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E="
  crossorigin="anonymous"></script>

  <form>
    <input type="text" name="form_230f1916-6f5f-460d-a6d9-5d2233010684" id="form_230f1916-6f5f-460d-a6d9-5d2233010684" />
  </form>
  <script>
    $(function() {
      //set the value of this field to $lastSegment
      $("#form_230f1916-6f5f-460d-a6d9-5d2233010684").val( '<?php echo $lastSegment; ?>' );
      //console.log($("#form_230f1916-6f5f-460d-a6d9-5d2233010684"));
    })
  </script>