Forum Moderators: coopster

Message Too Old, No Replies

Dynamic form elements

how to retrieve?

         

wigwambam

8:57 pm on May 11, 2006 (gmt 0)

10+ Year Member



I have a page which is built dynamically. On the page is a number of checkboxes, with unique generated names, for example:

job1
job24
job55
job100
...
..
job495

The user is able to select the jobs by ticking them.

When the form is posted, how do I retrieve the ticked boxes? I need their names.

It was easily done in ASP, but I can't seem to find a PHP equivalent. Any help appreciated.

coopster

9:14 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, wigwambam.

You need to name your input element with brackets.

<input name="jobs[]" type="checkbox" />

[php.net...]

eelixduppy

9:19 pm on May 11, 2006 (gmt 0)



hello

You could try something like this, assuming that the checkboxes were the only fields in your form.

form.php


print "
<form action='submit.php' method='post'>
$job_number<input type='checkbox' name='$job_number' value='$job_number'>

<!--more checkboxes depending on how you want it to be printed-->
</form>
";

submit.php


print_r($_POST);

This just prints out all of the selected ones. If you want to do something with them, you could try something like this:


$len = count($_POST);
$keys = array_keys($_POST);
for($i = 0; $i < $len; $i++)
{
$key = $keys[$i];
$job = $_POST[$key];
echo $job."<br>";
}

I hope this works because i haven't tested it. Good luck

eelix

eelixduppy

9:20 pm on May 11, 2006 (gmt 0)



Looks like i took too long to type my response :)

eelix

jatar_k

9:23 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



us mods are quick eelixduppy ;)

coopster

9:29 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, just making the afternoon rounds is all ;-)

wigwambam

9:30 pm on May 11, 2006 (gmt 0)

10+ Year Member



Thanks a lot everyone - and how quick were your replies? Amazing, I've wasted hours on this. Wished I'd come here first. :-)

Its getting late here in the UK + I'm having a couple of beers so I will have a go in the morning. If I'm still struggling I know where to ask.

Cheers and Beers,
wigwambam