A _post question I guess

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-29-2003
John Taylor-Johnston
 
Posts: n/a
Default A _post question I guess

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
Reply With Quote
  #2 (permalink)  
Old 09-29-2003
Brad Pauly
 
Posts: n/a
Default Re: [PHP] A _post question I guess

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
Reply With Quote
  #3 (permalink)  
Old 09-29-2003
Tom Rogers
 
Posts: n/a
Default Re: [PHP] A _post question I guess

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
Reply With Quote
  #4 (permalink)  
Old 09-29-2003
John Taylor-Johnston
 
Posts: n/a
Default Re: [PHP] A _post question I guess

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.

Reply With Quote
  #5 (permalink)  
Old 09-29-2003
Brad Pauly
 
Posts: n/a
Default Re: [PHP] A _post question I guess

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
Reply With Quote
  #6 (permalink)  
Old 09-29-2003
John Taylor-Johnston
 
Posts: n/a
Default Re: [PHP] A _post question I guess

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:14 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0