0

This question builds off of this question I had earlier... I have a php form that submits fine. I am adding an "ADD MORE" feature to it that adds this entire fieldset again.

//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";

}

If the user clicks more, then this foreach runs through the added fields:

    $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";
    }

It will take the 1st fields, that is the php added one... then the 1st fieldset that is added via javascript (user added), but it will not take the 2nd or 3rd... so my data ends up looking like:

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

Why is that foreach not picking up the addQues() a second time?

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) "" }

the var_dump for the info I am getting would be: 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" }

2
  • What is the output of var_dump($_REQUEST);? Commented May 29, 2012 at 17:25
  • @Viktor Added the var_dump there. There are some values at the top that are not being set right away ie... name,email,add,citystate,phone1,phone2,reqtype... Thanks. Commented May 29, 2012 at 17:31

2 Answers 2

2

If I understand you correctly, you want to have a form where you can fill in details about file permission requests, and add more requests to the same form dynamically.

You are probably not setting the names of the form fields correctly. If the first and second fieldset works, but not the others, The one originally in the form has a different naming convention than the ones added dynamically, and the ones added dynamically are conflicting with each other.

I recommend that you use Chrome to test it, and open up the developer tools to see the live HTML code of the page as it is updated by the Javascript.

Your last question had form fields named like this:

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

If you want several fieldsets like this, you need to use array notation, as pointed out in the answer to your last question.

It can be a bit tricky, unless you know what you are doing. If you just add array brackets, like this;

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

...you data will be submitted, but they will not be grouped nicely. It would be better to group them as objects;

<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>

That way, each added requests data is kept grouped nicely. This solution demands that you set the numerical index properly in the javascript adding the fieldset.

Sign up to request clarification or add additional context in comments.

2 Comments

That's indeed a handy way to get each set separately if that makes the post-processing easier. Nice!
OK, that solution works really well... I used this to get the data... Thanks PHP Manual...$a=$_REQUEST['request']; foreach ($a as $value1) { foreach ($value1 as $k => $value2) { echo $k; echo " $value2 <br />"; } }
1

As you can see in the var_dump output, addfield is a field of type array with 21 elements in it. Specifically, it contains the three sets of field values you mention earlier, but not organized in any way. That's why you get texts only for the first set (values 0...6 for $k) when you loop through $_REQUEST['addfield'].

If I were you, I'd probably name the dynamically added fields in the same way as the static fields, ie. userpermissiongroup[], addreadaccess[] etc., and then process all fields as arrays.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.