I've been experimenting with Pjax and love it so far. It works great, but I've run into an issue. When submitting a form (post) with pjax, everything works, but I'm getting a "PHP Notice: Undefined index: name" in the error log.
Here's my code for submitting the form:
$(document).on('submit', 'form[data-pjax]', function(event) {
event.preventDefault();
$.pjax.submit(event, '#containercontainer');
return false;
});
I've got all the required .js files included but not here for simplicity.
Here's an abridged version of my form:
<form data-pjax method="POST" action="add-process.php" id="addform">
<div class="row">
<div class="col-sm-5">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" placeholder="Name" name="name" autocomplete="off" autofocus>
</div>
</div>
...
</div>
<button id="submit_btn" type="submit" class="btn btn-success btn-block" style="font-weight:bold;">ADD</button>
</form>
In the add-process.php file, I'm getting the variables with $name = $_POST['name']; but the error log says undefined index for these lines.
UPDATE:
I changed my PHP code to include the recommended isset() as seen below:
// GET INFO FROM FORM
if(isset($_POST['userID'])) {
$userID = $_POST['userID'];
}
if(isset($_POST['reason'])) {
$reason = $_POST['reason'];
}
if(isset($_POST['otherreason'])) {
$otherreason = $_POST['otherreason'];
}
if($reason == 3) {
$reason = $otherreason;
}
if(!is_numeric($userID)) {
echo 'User ID not numeric!';
exit();
}
That fixed several things, but I'm still getting errors in the log:
PHP Notice: Undefined variable: reason
PHP Notice: Undefined variable: userID
Again, Thank you for any help!