You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telegram迷你应用表单移动端提交异常:请求为空且转GET方法求助

Telegram迷你应用表单提交移动端异常问题

电脑端Telegram迷你应用提交表单完全正常,但移动端提交同一表单时,请求自动使用GET方法,且请求数据为空。相关表单代码如下:

<form action="{{$route}}" method="POST" enctype="multipart/form-data">
    @method($method)
    @csrf

    <div class="form-group input-group">
        <div class="input-group-prepend">
            <div class="input-group-text">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon-container" viewBox="0 0 384 512">
                    <path fill="currentColor" d="M172.268 501.67C26.97 291.031 0 269.413 0 192 0 85.961 85.961 0 192 0s192 85.961 192 192c0 77.413-26.97 99.031-172.268 309.67C162.733 515.444 142.37 515.443 132.834 501.67zM192 272c44.183 0 80-35.817 80-80s-35.817-80-80-80-80 35.817-80 80 35.817 80 80 80z"/>
                </svg>
            </div>
        </div>
        <input type="text" id="location-input" placeholder="Добавить город" class="form-control" autocomplete="off">
    </div>
    <div id="suggestions-container" class="autocomplete-suggestions" style="display: none;"></div>

    <div id="selected-locations" class="selected-locations" style="margin-top: 10px;">
        @foreach($selectedCities as $city)
            <div class="selected-location">{{ $city }}</div>
        @endforeach
    </div>

    <div class="form-group">
        <label for="job_type">Выберите вакансии</label>
        <select id="job_type" name="job_type[]" class="form-control" multiple>
            @foreach($types as $type)
                <option value="{{ $type->id }}"
                        @if(in_array($type->id, $selectedCategories)) selected @endif>
                    {{ $type->name }}
                </option>
            @endforeach

        </select>
    </div>

    <input type="hidden" name="user_id" value="{{ $user_id }}">
    <input type="hidden" id="locations" name="locations" value="{{ implode(', ', $selectedCities) }}">

    <div id="selected-job-types" class="selected-locations" style="margin-top: 10px;"></div>

    <div class="form-group center">
        <button type="submit" class="btn-primary">Применить</button>
    </div>
</form>

修复方案

1. 移除不必要的表单编码类型

如果表单不需要上传文件,直接删除enctype="multipart/form-data"属性。Telegram移动端WebView对该属性存在兼容性问题,无文件场景下会触发提交行为异常。

2. 确保请求方法字段生效

Laravel的@method指令生成的隐藏字段可能被移动端WebView忽略,手动替换为原生HTML隐藏字段,放在@csrf之后:

@csrf
<input type="hidden" name="_method" value="{{ $method }}">

页面渲染后检查该字段是否存在,避免被其他JS代码意外移除。

3. 排查JavaScript干扰

检查地点选择相关的自动补全JS代码,确保:

  • 表单提交前正确更新locations隐藏字段的值
  • 没有阻止表单默认提交行为,或篡改表单method属性
  • 添加临时调试代码确认提交状态:
    document.querySelector('form').addEventListener('submit', function(e) {
        console.log('当前表单方法:', this.method);
        console.log('表单数据:', new FormData(this));
        // 测试时可注释下面一行,确认是否是JS导致异常
        // e.preventDefault();
    });
    

4. 验证路由地址有效性

确保{{$route}}生成的是绝对HTTPS URL,避免使用相对路径。Telegram移动端WebView对跨域或非HTTPS请求限制严格,可能导致提交时方法被强制转为GET。

内容的提问来源于stack exchange,提问作者Anton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 04:00:57