首页 > 解决方案 > 如何通过 $_POST 获取动态变量

问题描述

我有类似的东西:

<fieldset>
  {% if clientFriend %} 
    {% set cfInfo = clientFriend.info() %} 
  {% endif %}
  <div class="form-group">
    <label for="friendName" class="hidden"></label>
    <input type="text" class="form-control" placeholder="FIO"
       name="friend[{{ cfInfo.id }}][name]"
       {% if cfInfo.friend_name %} value="{{ cfInfo.friend_name }}" {% endif %}>
  </div>
  <div class="form-group">
    <label for="phoneFriend" class="hidden"></label>
    <input type="tel" class="form-control" placeholder="Phone"
      name="friend[{{ cfInfo.id }}][phone]"
      {% if cfInfo.phone_friend %} value="{{ cfInfo.phone_friend }}" {% endif %}>
  </div>
  <div class="form-group">
     <button class="btn btn-outline-blue btn-outline-blue-sm">
         Add new 
     </button>
  </div>
</fieldset>

我怎样才能得到这个动态变量$_POST

if ($_POST['friend[cfInfo.id][name]'])

不幸的是它不起作用。

标签: phpdynamictwig

解决方案


推荐阅读