Good afternoon, I would like to update thia question.
Below is the code for my form.
<?php
/*
* Template Name: Confirmation
*/
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="<?php bloginfo('stylesheet_directory'); ?>/tset.js"></script>
</head>
<body>
<form method="get" name="testForm" id="testForm" action="https://www.paygate.co.za/paywebv2/process.trans">
<table>
<tr>
<td><label for="firstName">Name</label></td>
<td><input type="text" id="firstName" name="firstName" /></td>
</tr>
<tr>
<td><label for="lastName">Surname</label></td>
<td><input type="text" id="lastName" name="lastName" /></td>
</tr>
<tr>
<td><label for="age">Age</label>
<td><input type="number" id="age" name="age" min="0" max="100" /></td>
</tr>
<tr>
<td><input type="hidden" name="myHiddenField" id="myHiddenField" value="this is hidden" /></td>
</tr>
<tr>
<td><button name="submit" id="submit">Update</button><td>
</tr>
</table>
</form>
</body>
</html>
here is the code for the php.
global $wpdb;
$table = "tset";
$data = array(
"First_Name" => $_POST["firstName"],
"Last_Name" => $_POST["lastName"],
"Age" => $_POST["age"],
);
array(
"%s",
"%s",
"%d",
);
$wpdb -> insert($table, $data);
$response = array("myHiddenField" => "this is now filled in");
echo json_encode($response);
and here is the script.
$j = jQuery.noConflict();
$j(document).ready(function(){
$j('#testForm').submit(submit_testForm);
});
function submit_testForm() {
$j.ajax({
url: "http://localhost/wordpress/wp-content/themes/responsive-mobile-child/tset.php",
type: "POST",
data: console.log($j('#testForm').serialize()),
dataType: 'json',
success: testForm_success
});
return false;
}
function testForm_success() {
$j("#myHiddenField").val(response.my_hidden_field);
document.forms["testForm"].submit();
The problem I am having is that the data received by Ajax appears not to be supported by the handler. For instance the data received by Ajax is
firstName=NAME&lastName=SURNAME&age=42&myHiddenField=this+is+hidden
This format appears to be incorrect for this request as I tested it at jsonlint.com and when validated it came up with the following.
Error: Parse error on line 1
firstName = NAME &
^
Expecting ‘STRING’, ‘NUMBER’, ‘NULL’, ‘TRUE’, ‘FALSE’, ‘{‘, ‘[‘, got ‘undefined’
Please help.
Please close this topic, I’m all over the place here. I am going to open a new one.