Having an issue with empty arrays

Joined
Apr 27, 2023
Messages
1
Reaction score
0
I've got a contact form that works great... as long as a checkbox is checked.

If there's nothing checked, I get an error in my error_log

26-Apr-2023 15:47:20 America/Los_Angeles] PHP Warning: Undefined array key "howfind" in /home1/bluehqwi/public_html/contact-us/AjaxForm.php on line 126
[26-Apr-2023 15:47:20 America/Los_Angeles] PHP Fatal error: Uncaught TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in /home1/bluehqwi/public_html/contact-us/AjaxForm.php:126
Stack trace:
#0 /home1/bluehqwi/public_html/contact-us/AjaxForm.php(126): implode(', ', NULL)
#1 /home1/bluehqwi/public_html/contact-us/AjaxForm.php(262): Ajax_Form->__construct()
#2 {main}
thrown in /home1/bluehqwi/public_html/contact-us/AjaxForm.php on line 126

Line 126 is:

$howfind = implode(', ', $_POST['howfind']);

Can anyone help me figure out what I need to do so if the person doesn't want to check a box that the script doesn't error out?

Thanks!
 
Joined
Sep 4, 2022
Messages
136
Reaction score
16
hello,

it's a Type mismatch, the "implode" function needs an Array as parameter 2.

I can't gess what you concretly need as fix.

both :
you can do :
PHP:
<?php

$array_content = implode(',',$_POST) ;
// this case will process all datas in your $_POST from client.
// $_POST is an array
// because $_POST['howfind'] is one single value, isn't it ?
?>

or you need to filter by JS, knowing if the checkbox is checked or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,056
Messages
2,570,439
Members
47,101
Latest member
DoloresHol

Latest Threads

Top