at test.php is...
<form action = "test1.php" method = "POST">
<p>
<b>Interests:</b>
<br>
<input type = "Checkbox" name = "interests[]" value =
"politics">Politics
<input type = "Checkbox" name = "interests[]" value =
"economy">Economy
<p>
<input type = "Submit" name = "submit" value = "Save">
</form>
</form>
at test1.php is...
<?
include("test2.php");
$fp = new FormProcessor();
$fp->valid(
"interests",
"array",
LETTERS,
'The interests are valid.',
'The interests are invalid!'
);
?>
at test2.php is...
<?
define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/');
class FormProcessor
{
private function getValue($field)
{
$_REQUEST{$field};
}
public function valid($field, $type, $pattern, $warn, $alert)
{
$value = $this->getValue($field);
foreach ($value as $checkbox)
{
if(!preg_match($pattern, $checkbox))
{
$this->alerts[$field] = $alert;
return false;
}
}
}
} 8 1557
Raistlin Majere schreef:
at test.php is...
...
whats the difference between this, and your posting from 11 minutes ago
???? (besides the thow additional questionmarks in the subject)
--
Luuk
Raistlin Majere wrote:
at test.php is...
<form action = "test1.php" method = "POST">
<p>
<b>Interests:</b>
<br>
<input type = "Checkbox" name = "interests[]" value =
"politics">Politics
<input type = "Checkbox" name = "interests[]" value =
"economy">Economy
<p>
<input type = "Submit" name = "submit" value = "Save">
</form>
</form>
at test1.php is...
<?
include("test2.php");
$fp = new FormProcessor();
$fp->valid(
"interests",
"array",
LETTERS,
'The interests are valid.',
'The interests are invalid!'
);
?>
at test2.php is...
<?
define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/');
class FormProcessor
{
private function getValue($field)
{
$_REQUEST{$field};
}
public function valid($field, $type, $pattern, $warn, $alert)
{
$value = $this->getValue($field);
foreach ($value as $checkbox)
{
if(!preg_match($pattern, $checkbox))
{
$this->alerts[$field] = $alert;
return false;
}
}
}
}
What happens/doesn't happen that leads you to say it is wrong? What is
it supposed to do? What DOES it do?
Why do expect people to go into your code while being mind readers as to
the objective/problem?
On 13 set, 15:37, Luuk <L...@invalid.lanwrote:
Raistlin Majere schreef:at test.php is...
..
whats the difference between this, and your posting from 11 minutes ago
???? (besides the thow additional questionmarks in the subject)
--
Luuk
test2.php is different
On 13 set, 15:51, sheldonlg <sheldonlgwrote:
Raistlin Majere wrote:
at test.php is...
<form action = "test1.php" method = "POST">
<p>
<b>Interests:</b>
<br>
<input type = "Checkbox" name = "interests[]" value =
"politics">Politics
<input type = "Checkbox" name = "interests[]" value =
"economy">Economy
<p>
<input type = "Submit" name = "submit" value = "Save">
</form>
</form>
at test1.php is...
<?
include("test2.php");
$fp = new FormProcessor();
$fp->valid(
* * "interests",
* * "array",
* * LETTERS,
* * 'The interests are valid.',
* * 'The interests are invalid!'
* * );
?>
at test2.php is...
<?
define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/');
class FormProcessor
{
* * private function getValue($field)
* * {
* * * * $_REQUEST{$field};
* * }
* * public function valid($field, $type, $pattern, $warn, $alert)
* * {
* * * * $value = $this->getValue($field);
* * * * foreach ($value as $checkbox)
* * * * {
* * * * * * if(!preg_match($pattern, $checkbox))
* * * * * * {
* * * * * * * * $this->alerts[$field] = $alert;
* * * * * * * * return false;
* * * * * * }
* * * * }
* * }
}
What happens/doesn't happen that leads you to say it is wrong? *What is
it supposed to do? *What DOES it do?
If no box, any box or all boxes are checked, nothing should happen,
but I am getting a "Warning: Invalid argument supplied for foreach()
in C:\AppServ\www\intermediary\accounts\test2.php on line 15".
Why do expect people to go into your code while being mind readers as to
the objective/problem?
The objective is to check if there is any invalid value in the
interests array. The problem is that the value variable or the
interests array is an invalid argument to the foreach loop, but I do
not know why.
I thought people were going to run the code and see the error message,
but thinking about it again, why would people run the code? LOL!
Raistlin Majere wrote:
On 13 set, 15:51, sheldonlg <sheldonlgwrote:
>Raistlin Majere wrote:
>>at test.php is... <form action = "test1.php" method = "POST"> <p> <b>Interests:</b> <br> <input type = "Checkbox" name = "interests[]" value = "politics">Politics <input type = "Checkbox" name = "interests[]" value = "economy">Economy <p> <input type = "Submit" name = "submit" value = "Save"> </form> </form> at test1.php is... <? include("test2.php"); $fp = new FormProcessor(); $fp->valid( "interests", "array", LETTERS, 'The interests are valid.', 'The interests are invalid!' ); ?> at test2.php is... <? define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/'); class FormProcessor { private function getValue($field) { $_REQUEST{$field}; } public function valid($field, $type, $pattern, $warn, $alert) { $value = $this->getValue($field); foreach ($value as $checkbox) { if(!preg_match($pattern, $checkbox)) { $this->alerts[$field] = $alert; return false; } } } }
What happens/doesn't happen that leads you to say it is wrong? What is it supposed to do? What DOES it do?
If no box, any box or all boxes are checked, nothing should happen,
but I am getting a "Warning: Invalid argument supplied for foreach()
in C:\AppServ\www\intermediary\accounts\test2.php on line 15".
That means that the array is empty.
>
>Why do expect people to go into your code while being mind readers as to the objective/problem?
The objective is to check if there is any invalid value in the
interests array. The problem is that the value variable or the
interests array is an invalid argument to the foreach loop, but I do
not know why.
See above.
>
I thought people were going to run the code and see the error message,
but thinking about it again, why would people run the code? LOL!
Right.
sheldonlg wrote:
Raistlin Majere wrote:
>On 13 set, 15:51, sheldonlg <sheldonlgwrote:
>>Raistlin Majere wrote: at test.php is... <form action = "test1.php" method = "POST"> <p> <b>Interests:</b> <br> <input type = "Checkbox" name = "interests[]" value = "politics">Politics <input type = "Checkbox" name = "interests[]" value = "economy">Economy <p> <input type = "Submit" name = "submit" value = "Save"> </form> </form> at test1.php is... <? include("test2.php"); $fp = new FormProcessor(); $fp->valid( "interests", "array", LETTERS, 'The interests are valid.', 'The interests are invalid!' ); ?> at test2.php is... <? define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/'); class FormProcessor { private function getValue($field) { $_REQUEST{$field}; } public function valid($field, $type, $pattern, $warn, $alert) { $value = $this->getValue($field); foreach ($value as $checkbox) { if(!preg_match($pattern, $checkbox)) { $this->alerts[$field] = $alert; return false; } } } } What happens/doesn't happen that leads you to say it is wrong? What is it supposed to do? What DOES it do? If no box, any box or all boxes are checked, nothing should happen,
According to this line, you've specified all the possibilities and
nothing should ever happen. Under what conditions (nothing is left
here) SHOULD something happen?
>but I am getting a "Warning: Invalid argument supplied for foreach() in C:\AppServ\www\intermediary\accounts\test2.php on line 15".
That means that the array is empty.
1 - Use $_POST, not $_REQUEST. You should know whether what came in was
via a post or via the URL. While $_REQUEST will get the result, it is
very sloppy coding. (If I saw this in an example of someone's work, it
would strongly influence me to not hire that person).
2 - The array $value in test2.php is empty. That means that it is not
getting the filled from the method getValue($field). A quick look at
that method reveals the problem. You need to change the one line (as
written) in it to:
return $_REQUEST($field);
(Use $_POST or $_GET instead). What you have written does not return
any value. That is why it remains empty.
On Sat, 13 Sep 2008 21:27:12 -0400, sheldonlg wrote:
Raistlin Majere wrote:
>If no box, any box or all boxes are checked, nothing should happen, but I am getting a "Warning: Invalid argument supplied for foreach() in C:\AppServ\www\intermediary\accounts\test2.php on line 15".
That means that the array is empty.
That's not quite right - an empty array is a valid argument to foreach.
The problem is that the argument is not an array - it's probably null.
I V wrote:
On Sat, 13 Sep 2008 21:27:12 -0400, sheldonlg wrote:
>Raistlin Majere wrote:
>>If no box, any box or all boxes are checked, nothing should happen, but I am getting a "Warning: Invalid argument supplied for foreach() in C:\AppServ\www\intermediary\accounts\test2.php on line 15".
That means that the array is empty.
That's not quite right - an empty array is a valid argument to foreach.
The problem is that the argument is not an array - it's probably null.
Quite right. I was a little sloppy in my statement. That is why I
generally define it first with $variable = array() before trying to fill
the array which, itself, is before a foreach. Thanks for the correction. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from...
|
by: titan0111 |
last post by:
#include<iostream>
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;
class snowfall
{
private:
int ft;
|
by: E. Robert Tisdale |
last post by:
What makes a good C/C++ programmer?
Would you be surprised if I told you that
it has almost nothing to do with your knowledge of C or C++?
There isn't much difference in productivity, for...
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode...
|
by: Madhur |
last post by:
Hello
what about this nice way to open a file in single line rather than using
if and else.
#include<stdio.h>
void main()
{
FILE *nd;
clrscr();...
|
by: Cherrish Vaidiyan |
last post by:
Frinds,
Hope everyone is doing fine.i feel pointers to be the most toughest
part in C. i have just completed learning pointers & arrays related
portions. I need to attend technical interview on...
|
by: Keith K |
last post by:
Having developed with VB since 1992, I am now VERY
interested in C#. I've written several applications with
C# and I do enjoy the language.
What C# Needs:
There are a few things that I do...
|
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
|
by: Pyenos |
last post by:
import cPickle, shelve
could someone tell me what things are wrong with my code?
class progress:
PROGRESS_TABLE_ACTIONS=
DEFAULT_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=
|
by: Siong.Ong |
last post by:
Dear all,
my PHP aims to update a MySQL database by selecting record
one by one and modify then save.
Here are my PHP, but I found that it doesnt work as it supposed to be,
for example, when...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |