This is a discussion on A _post question I guess within the PHP General forums, part of the PHP Programming Forums category; I have a form. It has any number of hidden fields, named "exercise 1-100". Their names all ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a form. It has any number of hidden fields, named "exercise 1-100". Their names all start with "exercise" as in:
<input type=hidden name=exercise1> .... ? <input type=hidden name=exercise11> any number fo these possible ... <input type=hidden name=exercise71> How can I create one scipt that will recognise all of them? Any number of them. My idea is a bit like formmail.pl that reads any old field and mails it. Mine will read any number of "exercise" fields. John |
|
|||
|
John Taylor-Johnston wrote:
> I have a form. It has any number of hidden fields, named "exercise 1-100". Their names all start with "exercise" as in: > > <input type=hidden name=exercise1> > ... ? > <input type=hidden name=exercise11> > any number fo these possible ... > <input type=hidden name=exercise71> > > How can I create one scipt that will recognise all of them? Any number of them. My idea is a bit like formmail.pl that reads any old field and mails it. Mine will read any number of "exercise" fields. You could just loop over the _POST array. foreach ($_POST as $field_name => $field_value) { $content .= "$field_name = $field_value\n"; } Then just email $content. You could filter out the excerciseN fields if you only wanted to send those. - Brad |
|
|||
|
Hi,
Tuesday, September 30, 2003, 1:41:11 AM, you wrote: JTJ> I have a form. It has any number of hidden fields, named "exercise JTJ> 1-100". Their names all start with "exercise" as in: JTJ> <input type=hidden name=exercise1> JTJ> ... ? JTJ> <input type=hidden name=exercise11> JTJ> any number fo these possible ... JTJ> <input type=hidden name=exercise71> JTJ> How can I create one scipt that will recognise all of them? Any JTJ> number of them. My idea is a bit like formmail.pl that reads any old field JTJ> and mails it. Mine will read any number of "exercise" fields. JTJ> John name them as name="exercise[1]" then do if(isset($_POST['exercise'])){ foreach($_POST['exercise'] as $key=>$val){ echo 'Key '.$key.' val '.$val.'<br>'; } } -- regards, Tom |
|
|||
|
Ok, but the problem is that I will, might have other fields. I need to filter out just the exerciseN fields. Interesting though thanks,
John Brad Pauly wrote: > You could just loop over the _POST array. > > foreach ($_POST as $field_name => $field_value) { > $content .= "$field_name = $field_value\n"; > } > > Then just email $content. You could filter out the excerciseN fields if > you only wanted to send those. |
|
|||
|
John Taylor-Johnston wrote:
> Ok, but the problem is that I will, might have other fields. I need to filter out just the exerciseN fields. Interesting though thanks, Then just look at $feild_name and see if it is one of the 'exercise' fields. foreach ($_POST as $field_name => $field_value) { if (stristr($field_name, 'exercise')) { $content .= "$field_name = $field_value\n"; } } - Brad |
|
|||
|
Brad. Perfect thanks.
> Brad Pauly wrote: > foreach ($_POST as $field_name => $field_value) { > if (stristr($field_name, 'exercise')) { > $content .= "$field_name = $field_value\n"; > } > } Tom, Not sure why, but wouldn't work >Tom Rogers wrote: >if(isset($_POST['exercise'])){ > foreach($_POST['exercise'] as $key=>$val){ > echo 'Key '.$key.' val '.$val.'<br>'; > } >} Thanks all. P.S. I try to surf and contribute when I see something I can answer. John |