doupiao9318
2019-04-21 13:37
浏览 75
已采纳

是否可以将表单中的数组作为隐藏字段传递? [重复]

This question already has an answer here:

I have a form that submits various fields to create a new child job to the parent, but certain information from the parent job needs to be passed to the new job. There are a lot of fields that need to be passed to the new job, so I am wondering if it's possible to pass an array as a hidden field to a form.

I have searched online and found different options, such as passing the array as a concatenation, but I have too many fields to pass over. $job is the array I want to pass.

<form method="post" action="##">
    <input type="hidden" name="job" value="<?php echo $job; ?>">
</form>

The error I got with the code above is "array to string conversion", which makes sense, but how do I get around it? There are many fields (probably close to 60) which need to be passed, so doing them one by one is not practical.

Any advice would be much appreciated.

</div>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • 使用HTML表单隐藏元素传递数组 8 answers

    我有一个提交各种字段以创建新子项的表单 作业到父作业,但父作业中的某些信息需要传递给新作业。 有很多字段需要传递给新作业,所以我想知道是否可以将数组作为隐藏字段传递给表单。

    我在线搜索 并找到了不同的选项,例如将数组作为连接传递,但是我有太多的字段要传递。 $ job是我要传递的数组。

     &lt; form method =“post”action =“##”&gt; 
    &lt; input type =“hidden”  name =“job”value =“&lt;?php echo $ job;?&gt;”&gt; 
    &lt; / form&gt; 
       
     
     

    我收到的错误 上面的代码是“数组到字符串转换”,这是有道理的,但我该如何解决它? 有许多领域(可能接近60个)需要通过,所以逐一进行这些领域是不切实际的。

    任何建议都将不胜感激。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshi4078 2019-04-21 13:44
    已采纳

    You can pass the id of the parent job in the hidden field, on form submit action you can get the parent id and retrieve the information of that job.

    <input type="hidden" name="parent_job_id" value="<?php echo $jobId; ?>">
    

    Make sure which index holding the id of the parent job.

    It seems $job is an array, you can not echo it, you can echo its index.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题