bob jomes bob jomes - 4 months ago 11
HTML Question

dont add rule for certain input field

So I have input fields and when they are submitted, I check to see if their inputted text appears in an array:

<form method="post">
<input type="text" name="1">
<input type="text" name="2">
<input type="text" name="3">
<input type="submit" name="submit">
</form>

<?php

if(isset($_POST['submit'] {

$array = array('432423', '434', '3', '2', '213');

$success = true;

foreach ($_POST as $key=>$value) {
if (!empty($value) && $key != "submit") {
if (!in_array($value, $array)) {
$success = false;
}
}
}


var_dump($success);
// TRUE if all contains, FLASE if any one doesn't contain

}

?>


But if I wanted a certain input field not to have to be checked against the array, how would I do this

Answer

Then you probably want to check for another $key != something?

E.g.

if (!empty($value) && $key != "submit" && $key != "2") {
   ...

This would exclude the second input...