Computers and Technology

I am unable to check if my $check array is empty or contains information passed via post from a checkbox group.

if ($_POST) {
if ($error_array = validate_form() ) {
show_form ($error_array);
}
else {
process_form( );
}
}
else {
show_form ( );
}

function show_form($errors = []) {
include ("survey_inc. php");
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);

return $data;
}

// valid name, valid email, not empty check box, and valid radio and not empty.
function validate_form() {
$errors = []; // start with empty array
$name = test_input($_POST['name']);
$email = test_input($_POST['email']);
$check = test_input($_POST['bucket']);
$radio = test_input($_POST['species']);

// checking to see if name is 2+ characters
if (strlen($name) < 2) {
$errors[] = "Name is too short or empty.";
}

// check email
if (! filter_var($email, FILTER_VALIDATE_EMAIL) ){
$errors[] = "Enter a valid email.";
}

// check check group
if (empty($check)) {
$errors[] = "Please select a Bucket list item, even if it's not on your list.";
}
/*if (!empty($check)) {
switch ($check) {
case "skydiving":
break;
case "rocky_mountain_climbing":
break;
case "bull_riding":
break;
default:
$errors[] = "Please select a bucket list item...from the list.";
}
}
else {
$errors[] = "Please select a bucket list item...even if it isn't one on your list!";
}
if (!empty($check)) {
if (in_array($check, $bucket_arr)) {
$errors[] = "Please select a bucket list item...from the list.";
}
} else {
$errors[] = "Please select a bucket list item...even if it isn't one on your list!";
}*/

//check radio item
/*
if (!empty($radio)) {
switch ($radio) {
case "yes":
break;
case "no":
break;
case "other":
break;
default:
$errors[] = "Please select your species...from the list.";
}
}
else {
$errors[] = "Please select your species...even if you lie!";
}
*/
if (!empty($radio)) {
if (in_array($radio, $species_arr)) {
$errors[] = "Please select your species...from the list.";
}
} else {
$errors[] = "Please select your species...even if you lie!";
}

return $errors;
}

function process_form() {
$name = test_input($_POST['name']);
$email = test_input($_POST['email']);
$check = test_input($_POST['bucket']);
$radio = test_input($_POST['species']);

echo $name."\n", $email."\n", $check."\n", $radio."\n";
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:40, penelopymorales24
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
image
Computers and Technology, 22.06.2019 23:30, riah133
Creating "smart interfaces" in all sectors of industry, government, and the public arena is one of the fastest growing hct areas. these interfaces model, interpret, and analyze such human characteristics as speech, gesture, and vision. the field of biometrics, in which humans authenticate themselves to machines, is an area of considerable interest to hct practitioners. fingerprint scans are one of the most frequently used biometric options, and this article, biometric student identification: practical solutions for accountability & security in schools, makes a case for the implementation of fingerprint scans in schools. critique the article, and answer the following questions: according to the author, what are the main benefits of adopting fingerprint scans in schools for student identification? according to the author, what are the main drawbacks of adopting fingerprint scans in schools for student identification? do you agree with the author's assessment of the pl
Answers: 2
image
Computers and Technology, 23.06.2019 00:10, witerose701
Write a function so that the main0 code below can be replaced by the simpler code that calls function mphandminutes tomiles0. original main0 int main) l double milesperhour-70.0; double minutestraveled = 100.0; double hourstraveled; double milestraveled; hourstraveled = minutestraveled / 60.0; milestraveled = hourstraveled * milesperhour; cout < "miles" 2 using namespace std; 4 /* your solution goes here/ 6 int maino 1 test passed 7 double milesperhour 70.0 all tests passed 8 double minutestraveled 100.0; 10 cout < < "miles: " < < mphandminutestomiles(milesper-hour, minutestraveled) < < endl; 12 return 0; 13
Answers: 1
image
Computers and Technology, 23.06.2019 06:30, wwesuplexcity28
To become an audio technician, the most successful tactics might include the following. (select all that apply). learning how to persuade other people gaining different types of experience in audio technology learning as much as possible about art history establishing a reputation as a reliable professional
Answers: 1
Do you know the correct answer?
I am unable to check if my $check array is empty or contains information passed via post from a chec...

Questions in other subjects:

Konu
Chemistry, 09.10.2021 14:00
Konu
Mathematics, 09.10.2021 14:00