Jump to content

Add Multiple Form Inputs onClick, then echo out on submit


buildakicker

Recommended Posts

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!

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.