buildakicker Posted May 28, 2012 Share Posted May 28, 2012 I have a form: <fieldset> <legend>Request Access Change(s) To Exisiting Folder</legend> <div class="topinfo"> <p><span class="required">* Required Fields</span></p> </div> <label for="fullpath"><span class="required">*Full Path of folder to change access:</span></label> <input name="fullpath" id="it10" type="text" size="50" maxlength="50" /> <br /> <small>Example: j://this/is/my/folder</small><br /> <div class="bgdiff"> <label for="userpermissiongroup">User Permission Group to be changed:</label> <input name="userpermissiongroup" type="text" id="it11" size="50" maxlength="50" /> <small>If Known...</small></div> <br /> <label for="addreadaccess">Additional users requiring read access:</label> <input name="addreadaccess" type="text" id="it12" size="15" maxlength="15" /> <br /> <small>AD Username</small><br /> <div class="bgdiff"> <label for="addauthoraccess">Additional users requiring author access:</label> <input name="addauthoraccess" type="text" id="it13" size="12" maxlength="12" /> <br /> <small>AD Username</small></div> <br /> <label for="removeaccess">Users to be removed from access:</label> <input name="removeaccess" type="text" id="it14" size="12" maxlength="12" /> <br /> <small>AD Username</small><br /> <div class="bgdiff"> <label for="supervisor"><span class="required">*Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes:</span></label> <input name="supervisor" type="text" id="it15" size="30" maxlength="30" /> <br /> <small>AD Username</small></div> <br/> <label for="phoneapprover"><span class="required">*Phone number of approving official: </span></label> <input name="phoneapprover" type="text" id="it16" size="30" maxlength="30" /> <br /> <small>999-999-9999</small><br /> <!-- id to adding more fields on demand to ---> <div id="addmore"></div> <input type="button" onClick="addInput()" name="add" value="Add More Requests" /> </fieldset> On Submit, this form calls a php script that just takes all these fields and echos them out for me to see for now. I would like to add the ability to add this whole fieldset again, if the user would like on click. I have a javascript "addInput()" function that just adds all these fields again: var fields = 0; function addInput() { /*if (addfields != 5) {*/ document.getElementById('addmore').innerHTML += '<hr /><p align="center" class="redtext" id="top'+fields+'">------------ ADD NEXT ACCESS CHANGE REQUEST BELOW ------------</p>'; document.getElementById('addmore').innerHTML += '<label for="fullpath" id="fauxtop"><span class="required">*Full Path of folder to change access:</span></label><input name="addfield[]" id="it10-' + fields + '" type="text" size="50" maxlength="50" /><br /><small>Example: j:\\this\\new\\folder\\</small><br />'; document.getElementById('addmore').innerHTML += '<div class="bgdiff"><label for="userpermissiongroup">User Permission Group to be changed:</label><input name="addfield[]" id="it11-' + fields + '" type="text" size="50" maxlength="50" /><small>If Known...</small></div><br />'; document.getElementById('addmore').innerHTML += '<label for="addreadaccess">Additional users requiring read access:</label><input name="addfield[]" id="it12-' + fields + '" type="text" size="15" maxlength="15" /><br /><small>AD Username</small><br />'; document.getElementById('addmore').innerHTML += '<div class="bgdiff"><label for="addauthoraccess">Additional users requiring author access:</label><input name="addfield[]" id="it13-' + fields + '" type="text" size="12" maxlength="12" /><br /><small>AD Username</small></div><br />'; document.getElementById('addmore').innerHTML += '<label for="removeaccess">Users to be removed from access:</label><input name="addfield[]" id="it14-' + fields + '" type="text" size="12" maxlength="12" /><br /><small>AD Username</small><br />'; document.getElementById('addmore').innerHTML += '<div class="bgdiff"><label for="supervisor"><span class="required">*Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes:</span></label><input name="addfield[]" id="it15-' + fields + '" type="text" size="30" maxlength="30" /><br /><small>AD Username</small></div><br/>'; document.getElementById('addmore').innerHTML += '<label for="phoneapprover"><span class="required">*Phone number of approving official: </span></label><input name="addfield[]" id="it16-' + fields + '" type="text" size="30" maxlength="30" /><br /><small>999-999-9999</small><br />'; fields += 1; } I have been using a foreach loop to display the form inputs: foreach($_REQUEST['addfield'] as $value) { echo "$value <br />"; } I would like to have each of the fields display the $value and have information before each like so: Full Path of folder to change access: $value; User Permission Group to be changed: $value; That is where my problem is... seems simple, but I am not getting it to work. Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/263283-add-multiple-form-inputs-onclick-then-echo-out-on-submit/ Share on other sites More sharing options...
Barand Posted May 28, 2012 Share Posted May 28, 2012 give the inputs names like name='fullpath[]' Thay way each one is posted as an array. Quote Link to comment https://forums.phpfreaks.com/topic/263283-add-multiple-form-inputs-onclick-then-echo-out-on-submit/#findComment-1349334 Share on other sites More sharing options...
buildakicker Posted May 29, 2012 Author Share Posted May 29, 2012 Hi, thanks for the response. They already have name: name="addfield[]" I get them in the array no problem, my issue is putting text before each of the results I am echoing out. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/263283-add-multiple-form-inputs-onclick-then-echo-out-on-submit/#findComment-1349494 Share on other sites More sharing options...
Barand Posted May 29, 2012 Share Posted May 29, 2012 Create an array for the text with same keys as the post names Quote Link to comment https://forums.phpfreaks.com/topic/263283-add-multiple-form-inputs-onclick-then-echo-out-on-submit/#findComment-1349495 Share on other sites More sharing options...
buildakicker Posted May 29, 2012 Author Share Posted May 29, 2012 this worked thanks... $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($a as $k => $value) { echo "$addQues[$k] $value <br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/263283-add-multiple-form-inputs-onclick-then-echo-out-on-submit/#findComment-1349546 Share on other sites More sharing options...
buildakicker Posted May 29, 2012 Author Share Posted May 29, 2012 I ran into an interesting issues... this foreach will return the first added field correctly, however it will not add a 2nd or 3rd field with the data from the addQues(); For example: First Result: 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 Second: i:\new i group urusa mmalone jjon yokis 888-999-555 Third: u:\ u group phammer midnite bmarley gdead 777-444-2222 ect... Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/263283-add-multiple-form-inputs-onclick-then-echo-out-on-submit/#findComment-1349559 Share on other sites More sharing options...
buildakicker Posted May 29, 2012 Author Share Posted May 29, 2012 Ok, did a little change.. .but this works. Thanks to the web! Added input names like so: name="request['+fields+'][Full Path of folder to change access:]" Added a number to them each time the user wanted to add a new field... Then processed them like so: $a=$_REQUEST['request']; foreach ($a as $value1) { foreach ($value1 as $k => $value2) { $note.= $k; $note.= $value2; } } Example ---- $k returns: Full Path of folder to change access: $value2 returns user input Quote Link to comment https://forums.phpfreaks.com/topic/263283-add-multiple-form-inputs-onclick-then-echo-out-on-submit/#findComment-1349611 Share on other sites More sharing options...
Barand Posted May 29, 2012 Share Posted May 29, 2012 Ok, did a little change.. .but this works. Thanks to the web! If you only knew how much we enjoy wasting our time on people seeking answers elsewhere Quote Link to comment https://forums.phpfreaks.com/topic/263283-add-multiple-form-inputs-onclick-then-echo-out-on-submit/#findComment-1349617 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.