/*--------------------------------------------------------------------------------------------------------------------------------
Parameters:
$formField1: The name of the first array
$formField2: The name of the second array
$formField1Comp areWith: String to use as my comparison basis for first
array. Defaults to using $val unless it's 'key'
$formField2Comp areWith: String to use as my comparison basis for
second array. Same default as $formField1Comp areWith
$match: Boolean to look for exact key or value match (default will
compare if instances compare true for both array)
---------------------------------------------------------------------------------------------------------------------------------*/
function isValidArrayCom pare($formField 1, $formField2,
$formField1Comp areWith = '', $formField2Comp areWith = '', $match = '')
{
// BOOLEAN TO COMPARE DIFFERENT FORM ELEMENT ARRAYS TOGETHER
reset($this->post);
if (!$formField1 && !$formField2) return false; // BLANK PARAMETERS
if (!in_array($for mField1, array_keys($thi s->errorMsgObjArr ay)) &&
!in_array($form Field2, array_keys($thi s->errorMsgObjArr ay))
) return false; // NOT IN ERROR MESSAGE OBJECT ARRAY
if (!in_array($for mField1, array_keys($thi s->post)) &&
!in_array($form Field2, array_keys($thi s->post))
) return false; // NOT IN GET/POST COLLECTION
$hasFoundValFor mField1 = false;
if (strcmp(strtolo wer($formField1 CompareWith), 'key') == 0 &&
strcmp(strtolow er($formField2C ompareWith), 'key') == 0) {
// KEY TO KEY ARRAY COMPARISON
if (@sizeof($this->post[$formField1]) > 0) { // FIRST ARRAY HAS KEYS
$hasFoundValFor mField1 = true; $hasFoundValFor mField2 = true;
foreach ($this->post[$formField1] as $key) {
if (@!in_array($ke y, array_keys($thi s->post[$formField2]))) { //
MATCHING KEY FOUND IN SECOND ARRAY
$hasFoundValFor mField2 = false;
break;
}
}
}
} elseif (strcmp(strtolo wer($formField1 CompareWith), 'key') == 0) {
// KEY TO VAL ARRAY COMPARISON
if (@sizeof($this->post[$formField1]) > 0) { // FIRST ARRAY HAS KEYS
$hasFoundValFor mField1 = true; $hasFoundValFor mField2 = true;
foreach ($this->post[$formField1] as $key) {
if (@!in_array($ke y, array_values($t his->post[$formField2]))) { //
MATCHING VAL TO KEY FOUND IN 2ND ARRAY
$hasFoundValFor mField2 = false;
break;
}
}
}
} elseif (strcmp(strtolo wer($formField2 CompareWith), 'key') == 0) {
// VAL TO KEY ARRAY COMPARISON
if (@sizeof($this->post[$formField1]) > 0) { // SECOND ARRAY HAS KEYS
$hasFoundValFor mField1 = true; $hasFoundValFor mField2 = true;
foreach ($this->post[$formField1] as $key => $val) {
if (!$key[$val] || strlen($key[$val]) == 0) {
$hasFoundValFor mField2 = false;
break;
}
}
}
} else {
// VAL TO VAL ARRAY COMPARISON
foreach ($this->post[$formField1] as $key => $val) {
if ($val && strlen($val) > 0 && !empty($val)) {
$hasFoundValFor mField1 = true; $hasFoundValFor mField2 = true;
if (@!in_array($va l, array_values($t his->post[$formField2]))) { //
MATCHING VAL FOUND IN SECOND ARRAY
$hasFoundValFor mField2 = false;
break;
}
}
}
}
if ($hasFoundValFo rmField1 && $hasFoundValFor mField2) return true;
return false;
}
My class method isValidArrayCom pare will be comparing two arrays found
within the form post (passed into the class becoming $this->post). The
method has to have the following conditions:
1) Both arrays can be enumerative or associative, or one can be
enumerative and the other associative
2) Both arrays have to be able to be compared either by key-to-key,
key-to-val, val-to-key, or val-to-val
I have run into snags when you have this unique case:
Array A comes from a checkbox group and thus is not only enumerative,
but DYNAMIC as well (that is, it will only have values you checked
prior and that's all!); Array B comes from a group of dropdowns; each
dropdown down is given the same name but its key is the corresponding
value of the checkbox to the left (like $myCheckbox[0] => 'A' maps to
$myDropdown['A'] => 5). I need to be sure that the comparison will be
either true or false depending on if the value of Array A is found as
a key-with-a-value in Array B, AND if the key-with-a-value in Array B
exists as a value in Array A.
That's just THAT case. There will be a WHOLE lot more variances, but
the 2 rules above will always be true. I thought my method would cover
them all but alas, it fails on the Array A - Array B scenario if I
check more of Array A than I select of Array B for each Array A
checkbox.
You can see why I want to find an out-of-the-box solution for form
validation! >:(
Phil 0 2711 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dan |
last post by:
Hello,
I have trouble with class calling. I am calling getvolume() with succes in
the function CreateCircle but it do not want to call it in ShowCircle()
function. I am staying in the same class. I thought that was the point of
encapsulation. When the function ShowCircle() is called I get very large
number -1.07374e+008
can anyone help me ?
|
by: Dennis |
last post by:
I have a class named "myclass" and an arraylist containing elements of type
"MyClass". I want to get the value of a property of "MyClass" (a string
type) for one of the arraylist elements.
I can get this using:
dim b as string
b = DirectCast(myarraylist(0),myclass).myproperty
However, I want to use an object to define the type "MyClass" like:
dim C as type = type.GetType(myarraylist(0))
|
by: rithish |
last post by:
I am on IE 6. I was trying out a simple xmlhttp function that send
GET/POST requests. However, IE throws an 'unspecified error' when I
call the 'setRequestHeader' method.
The function that I am trying out is give below. Am I doing something
wrong? Any help is greatly appreciated.
/*
|
by: Oleg Subachev |
last post by:
Is there other way of comparing two byte arrays
than iterating through the two and compare individual bytes ?
Oleg Subachev
|
by: I.M. !Knuth |
last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until
I started goofing around with this:
================================================================================
/* A function that returns a pointer-of-arrays to the calling function. */
#include <stdio.h>
int *pfunc(void);
| |
by: Fir5tSight |
last post by:
Hi All,
I have two identical PDF files, say file1 and file2. I used an API
package to extract the bitmap in each PDF file, say bitmap1 (in file1)
and bitmap2 (in file2). Since the bitmaps are same in both files, I
expect bitmap1.Equals (bitmap2) to return true. However, it's false.
FYI:
1) I've copied file1 to file2, therefore, the bitmap images in both
|
by: stromhau |
last post by:
Hi,
I have made a few classes in c++. They somehow cooperate doing some 3d stuff.
Basically it is a moving camera acting as a flight, i have placed a lot of objects around the scene together with a b-spline surfcae.
The problem class is the polygon class. this class read 3d files generates faces, edges and so on.
here are two of the building blocks(structs)
struct FACE{
|
by: Yen Kwoon |
last post by:
Note: This problem is related to gcc but after some back and forth in
group gnu.gcc.help it seems to have morph into more of a c++
specificiation question, hence the transplanting to this group.
The original post at gnu.gcc.help can be found at this link
http://groups.google.com/group/gnu.gcc.help/browse_thread/thread/ece55cbbd9c36270/2148a6c1ac6119e1?lnk=st&q=#2148a6c1ac6119e1
Here's the question:
class base {
|
by: Patient Guy |
last post by:
I am a newcomer to using PHP but not to programming (C, C++, Javascript).
I am playing around with classes and wanted to make a function that has a
method simply for producing either plain text or HTML output in a tabular
way a listing of the global variables in the = keyValue two-column
format. That's what the method listGlobals does.
I am stumped by the following error message:
PHP Catchable fatal error: Object of class phpEnv...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |