gpt4 book ai didi

php - foreach 第二次没有获取数组数据

转载 作者:行者123 更新时间:2023-11-28 21:01:51 25 4
gpt4 key购买 nike

此问题构建 off of this question I had earlier ...我有一个可以正常提交的 php 表单。我正在向其中添加“添加更多”功能,再次添加整个字段集。

//access changes
if ($reqtype=="accesschange"){
$subject="FORM: Request Access Change(s) To Exisiting Folder";
$note .="Full Path of folder to change access: $fullpath \n\n";
if($userpermissiongroup != ""){
$note .="User Permission Group to be changed: $userpermissiongroup \n";
}
if($addreadaccess != ""){
$note .="Additional users requiring read access: $addreadaccess \n";
}
if($addauthoraccess != ""){
$note .="Additional users requiring author access: $addauthoraccess \n";
}
if($removeaccess != ""){
$note .="Users to be removed from access: $removeaccess \n";
}
$note .="Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes: $supervisor \n\n";
$note .="Phone number of approving official: $phoneapprover \n";

}

如果用户单击更多,则此 foreach 会遍历添加的字段:

    $addQues = array(
"Full Path of folder to change access:",
"User Permission Group to be changed:",
"Additional users requiring read access:",
"Additional users requiring author access:",
"Users to be removed from access:",
"Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes:",
"Phone number of approving official:",
);

foreach($_REQUEST['addfield'] as $k => $value) {
$note .= "$addQues[$k] $value";
}

它将采用第一个字段,即 php 添加的字段...然后通过 javascript 添加的第一个字段集(用户添加),但不会采用第二个或第三个...所以我的数据结束看起来像:

Full Path of folder to change access: t:\this-drive User Permission Group to be changed: dv group Additional users requiring read access: jfla Additional users requiring author access: azann Users to be removed from access: dlint Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes: gpone Phone number of approving official: 888-888-7777

Full Path of folder to change access: o:\driveUser Permission Group to be changed: odrive groupAdditional users requiring read access: sjonesAdditional users requiring author access: pvalleUsers to be removed from access: kpowerData Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes: bzellPhone number of approving official: 777-777-7777

i:\new i group urusa mmalone jjon yokis 888-999-555

u:\ u group phammer midnite bmarley gdead 777-444-2222

为什么 foreach 没有再次获取 addQues() ?

VAR_DUMP $_REQUEST

array(22) { ["name"]=> string(1) " " ["email"]=> string(14) "" ["add"]=> string(0) "" ["citystate"]=> string(4) ", " ["phone1"]=> string(0) "" ["phone2"]=> string(0) "" ["reqtype"]=> string(12) "accesschange" ["newpath"]=> string(0) "" ["usersaccess"]=> string(0) "" ["ryesaccess"]=> string(0) "" ["approvingofficer"]=> string(0) "" ["sphone"]=> string(0) "" ["comments"]=> string(0) "" ["fullpath"]=> string(14) "t:\this-drive" ["userpermissiongroup"]=> string(8) "dv" ["addreadaccess"]=> string(9) "jflat" ["addauthoraccess"]=> string(5) "bzat" ["removeaccess"]=> string(5) "dlit" ["supervisor"]=> string(6) "lnat" ["phoneapprover"]=> string(12) "888-888-7777" ["addfield"]=> array(21) { [0]=> string(9) "o:\drive" 1=> string(12) "odrive group" [2]=> string(6) "sjones" [3]=> string(6) "pvae" [4]=> string(7) "kpow" [5]=> string(8) "bdez" [6]=> string(12) "777-777-7777" [7]=> string(7) "i:\new" [8]=> string(7) "i group" [9]=> string(5) "urusa" [10]=> string(7) "mmalone" [11]=> string(4) "jjon" [12]=> string(5) "yokis" [13]=> string(11) "888-999-555" [14]=> string(4) "u:\" [15]=> string(7) "u group" [16]=> string(7) "phammer" [17]=> string(7) "midnite" [18]=> string(7) "bmarley" [19]=> string(5) "gdead" [20]=> string(12) "777-444-2222" } ["c_id"]=> string(0) "" }

我得到的信息的 var_dump 是: var_dumb($_REQUEST['addfield']

array(21) { [0]=> string(9) "o:\drive" 1=> string(12) "drive group" [2]=> string(6) "sjones" [3]=> string(6) "pval" [4]=> string(7) "kpow" [5]=> string(8) "bdezl" [6]=> string(12) "777-777-7777" [7]=> string(7) "i:\new" [8]=> string(7) "i group" [9]=> string(5) "urusa" [10]=> string(7) "mmalone" [11]=> string(4) "jjon" [12]=> string(5) "yokis" [13]=> string(11) "888-999-555" [14]=> string(4) "u:\" [15]=> string(7) "u group" [16]=> string(7) "phammer" [17]=> string(7) "midnite" [18]=> string(7) "bmarley" [19]=> string(5) "gdead" [20]=> string(12) "777-444-2222" }

最佳答案

如果我理解正确的话,您希望有一个表单,可以在其中填写有关文件权限请求的详细信息,并动态向同一表单添加更多请求。

您可能没有正确设置表单字段的名称。如果第一个和第二个字段集有效,但其他字段集无效,则表单中最初的字段集与动态添加的字段集具有不同的命名约定,并且动态添加的字段集相互冲突。

我建议您使用 Chrome 对其进行测试,并打开开发人员工具来查看由 Javascript 更新的页面的实时 HTML 代码。

您的最后一个问题的表单字段的命名如下:

<fieldset>
<input name="fullpath" (...) />
<input name="userpermissiongroup" (...) />
<input name="addreadaccess" (...) />
(...)
</fieldset>

如果您想要多个这样的字段集,则需要使用数组表示法,如上一个问题的答案中所指出的。

这可能有点棘手,除非您知道自己在做什么。如果你只是添加数组括号,就像这样;

<fieldset>
<input name="fullpath[]" (...) />
<input name="userpermissiongroup[]" (...) />
<input name="addreadaccess[]" (...) />
(...)
</fieldset>
<fieldset>
<input name="fullpath[]" (...) />
<input name="userpermissiongroup[]" (...) />
<input name="addreadaccess[]" (...) />
(...)
</fieldset>

...您的数据将被提交,但它们不会被很好地分组。最好将它们分组为对象;

<fieldset>
<input name="request[0][fullpath]" (...) />
<input name="request[0][userpermissiongroup]" (...) />
<input name="request[0][addreadaccess]" (...) />
(...)
</fieldset>
<fieldset>
<input name="request[1][fullpath]" (...) />
<input name="request[1][userpermissiongroup]" (...) />
<input name="request[1][addreadaccess]" (...) />
(...)
</fieldset>

这样,每个添加的请求数据都会很好地分组。此解决方案要求您在添加字段集的 JavaScript 中正确设置数字索引。

关于php - foreach 第二次没有获取数组数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10803677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com