Click here to Skip to main content
15,797,961 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a WordPress project, I am inserting a PHP file to do some specific form code.
I wanted to change the form from a drop-down list to a group of checkboxes, and now I am having thousands of warning: undefined array or undefined variable:
function calculdebit()
	global $wpdb;
	$plateauType =  $_POST['plateauType'];

<div id="select-2" class="champ_outil">
					<label for="select-2-label">
                    Quel est le plateau type ?</label>
                    <select id="plateauType" name="plateauType[]">
							<!-- <option value="1">
                    </option> -->
							<option id="PLATEAU-1" value="2"  
                    <?= (isset($_POST['plateauType']) && 
                    $_POST['plateauType'] === '2') ? 'selected' : ''; ? 
                    >> plateau-1 </option>
							<option id="PLATEAU-2" value="3" 
                            <?= (isset($_POST['plateauType']) && 
                            $_POST['plateauType'] === '3') ? 
                     'selected' : ''; ?>> plateau-2 </option>
							<option id="PLATEAU-3" value="4" <?= 
                      (isset($_POST['plateauType']) && 
                      $_POST['plateauType'] === '4') ? 'selected' : ''; ? 
                      >> plateau-3 </option>
							<option id="PLATEAU-4" value="5" <?= 
                      (isset($_POST['plateauType']) && 
                      $_POST['plateauType'] === '5') ? 'selected' : ''; ? 
                      >> plateau-4 </option>
							<option id="PLATEAU-5" value="6"  <?= 
                      (isset($_POST['plateauType']) && 
                       $_POST['plateauType'] === '6') ? 'selected' : ''; ? 
                       >> plateau-5 </option>
            <pre> <?
            echo $plateauType[1]; ?> 

//trying to see if there is something in the variable but it gives this error too Warning: Trying to access array offset on value of type null.

What I have tried:

I've tried to add " @global var $name_of_variable" on the top of code it does not work, and I also tried to name the variable the same name in PHP and in HTML code.

Any help would be so much appreciated, because I am stuck for a week.
Updated 14-Sep-23 0:23am

1 solution

You did not show us the actual error message(s), so this is something of a guess. But the variable $plateauType only exists within the scope of the calculdebit function. So your reference at the bottom of the HTML posted above, will be undefined.
Share this answer
Member 16090050 11-Sep-23 12:05pm    
Yes, you re right, i have declared the variable on the top of the file as @global $plateauType, and it worked.
now am having a white page when I submit the form I can not even know what's the error
I've tried to put WP_DEBUG on true and it didn't change anything :/
Richard MacCutchan 11-Sep-23 12:07pm    
Sorry, but no one here can possibly guess what is happening on your system.
Member 16090050 11-Sep-23 12:09pm    
could I show you the code please to see
if you don't mind ?
because i've been stuck with it for weeks
Richard MacCutchan 11-Sep-23 12:37pm    
You need to find out where things are going wrong first. Once you have collected all the information you need to post it in your question above.
Member 16090050 12-Sep-23 7:25am    
Actually, this is the problem, i can not figure out where things are going wrong :/
Anyway I appreciate your answers :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900