I'm trying to call a function from within another function, and use the returned variable.
function getUserEmail($clean_useremail){
// Get the POST var
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$useremail = test_input($_POST["useremail"]);
}
// Santize
$clean_useremail = filter_var($useremail), FILTER_SANITIZE_EMAIL);
if isset($clean_useremail){
return $clean_useremail;
// here is where I want to run createXML() using $clean_useremail
}else{
echo 'Error, no email received from form.';
}
}
function createXML(){
// create xml
}
The first function getUserEmail()
is called when a form is submitted via POST. It should get the data from the form, sanitize it and store it.
The function createXML()
I want to run afterwards, and make use of the variable $clean_useremail
Can't you just call createXML
from within getUserEmail
?
function getUserEmail($clean_useremail){
// Get the POST var
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$useremail = test_input($_POST["useremail"]);
}
// Santize
$clean_useremail = filter_var($useremail), FILTER_SANITIZE_EMAIL);
if(isset($clean_useremail)){
createXML($clean_useremail);
return $clean_useremail;
// here is where I want to run createXML() using $clean_useremail
}else{
echo 'Error, no email received from form.';
}
}
function createXML(){
// create xml
}
Call it before you return $clean_useremail
and place isset($clean_useremail)
between ()