I'm having problems using the PHP GLOBALS array in a Joomla website. When the form is submitted, the function form_submit is called where the form information is checked for validity. For some reason, I can access my variables correctly outside the function, but when I try to access them through the GLOBALS array, nothing is found.
<?php
//THIS CODE CREATES THE ADD COURSE FORM
//CONNECT TO SERVER
require('../database2/includes/connect.php');
//GET LOGGED IN USER INFO
$user = JFactory::getUser();
$user_id = $user->id;
$user_name = $user->name;
$category_query = $conn->query('SELECT * FROM category');
$category_query->setFetchMode(PDO::FETCH_ASSOC);
$name = $_POST['name'];
$description = $_POST['description'];
$category_id = $_POST['dropdown'];
$crn = $_POST['crn'];
$password_init = $_POST['password_init'];
$password_rt = $_POST['password_rt'];
$password = md5($password_init);
function form_submit()
{
var_dump($GLOBALS['name']); //Dumps null
global $name //Doesn't work either
if (empty($name) || empty($description) || empty($crn) || empty($password_init) || empty($password_rt))
{
echo "<b style='color:red'>* $name</b><br>";
echo "<b style='color:red'>* $description</b><br>";
echo "<b style='color:red'>* $crn</b><br>";
echo "<b style='color:red'>* $password_init</b><br>";
echo "<b style='color:red'>* $password_rt</b><br>";
}
}
if(isset($_POST['Submit']))
{
var_dump($name); //Dumps correct value
form_submit();
}
?>
var_dump($name) prints the correct value, but $GLOBALS['name'] inside the form_submit does not. What is wrong with my code?