Hello everyone,
I have a question as to how to assign values to PHP variables after they are passed from the jQuery Ajax call, particularly through the data: specification. This is what the .ajax() call looks like:
$("#submissionform form").submit(function(e){
var origEmail = $('#go').val();
var confirmEmail = $("#confirmemail").val();
var name = $("#name").val();
var age = $("#age").val();
var country = $("#country").val();
$.ajax({
type: "POST",
dataType: 'json',
cache: false,
url: "Scripts/confirmform.php",
data: { origEmail: origEmail,
confirmEmail: confirmEmail,
name: name,
age: age,
country: country },
success: function(data){
testSecondResults(data);
}
});
});
});
I want to be able to receive those parameters into the PHP script for all the values into the following PHP script (filename: confirmform.php).
<?php
$instance = new CheckForm;
$instance -> checkSubmission();
class CheckForm
{
public function checkSubmission()
{
$response = array("validation" => " ", "message" => " ");
if ($_POST['country'] != "Select Country")
{
if (isset($_POST['confirmemail']) && isset($_POST['name']))
{
$origEmail = $_GET['go'];
$confirmEmail = $_POST['confirmemail'];
if ($origEmail == $confirmEmail)
{
$name = htmlspecialchars($_POST['name']);
$ageRange = $_POST['age'];
$country = $_POST['country'];
require_once('databasewriter.php');
$dbWriter = new DatabaseWriter;
$dbWriter -> writeUserToDatabase($confirmEmail, $name, $ageRange, $country, $category);
$response = array("validation" => "pass", "message" => 'Thanks for joining the e-mail list, ' . $name . ', under the e-mail address, ' . $confirmEmail . '.');
} else {
$response = array("validation" => "fail", "message" => 'E-mail addresses don\\'t match.');
die();
}
} else {
if (!isset($_POST['confirmemail'])){
$response = array("validation" => "fail", "message" => 'Confirmation e-mail not entered.');
} elseif (!isset($_POST['name'])) {
$response = array("validation" => "fail", "message" => 'Please enter a name.');
}
}
} else {
$response = array("validation" => "fail", "message" => 'Please select a country.');
}
echo json_encode($response);
}
}
?>
Maybe the solution is to use the âthisâ keyword or I donât know if a constructor is the right way.
For other info, this will process a second confirmation form that is activated after another form has received a valid e-mail address submission. I want to pass that value along to compare it with the âconfirmationâ e-mail address, but I donât have access to that data anymore as I am seeing the following error that relates to the first form data that I am trying to use the $_GET server variable to receive into this form- it doesnât like me trying to fetch the first form data again with $_GET. :crazy:
Notice: Undefined index: go in C:\xampp\htdocs\Scripts\confirmform.php on line 14