Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting dynamic form values. 1

Status
Not open for further replies.

ag1060

Programmer
Aug 26, 2011
27
US
Hello coders,

I'm trying to get form values from dynamic form (screenshot:
When the user clicks submit, I want to get the textfield value and the value of the checkbox right next to each other like:

Stage1 - 1 (checked)
Stage2 - 0 (unchecked)

So far, I have the code to get the textfields values but not the checkbox values next to each other:

Code:
	while (list ($key,$status) = @each ($_POST['stage'])){ 
//echo "$val,"; 

	while (list ($key,$status1) = @each ($_POST['stage_status'])){ 



  echo "$status<br>";
 echo "$status1<br>";
   }
}

I know that's some bad coding practice but I was wondering how can I achieve what I've stated with neat coding. I know there's a way and any help is appreciated.


Thanks in advance.
 
only checked checkboxes will be submitted. so make sure that you explicitly number your checkboxes and fields as so

Code:
<form>
<input type="text" name="text[0]" /><input type="checkbox" name="completed[0]" value="1"/>
...
</form>

then in your receiving script

Code:
foreach ($_POST['text'] as $key=>$val):
 printf("%s - %s <br/>", htmlspecialchars(trim($val)), isset($_POST['completed'][$key]) ? "1 (checked)" : "0 (unchecked)");
endforeach;
 
jpadie,

I appreciate the help and it works just fine now :)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top