Я создал форму публикации вакансии, в которой пользователь заполняет форму, и после отправки формы работа должна отображаться на той же странице под ней.по какой-то причине возвращаемое описание работы и данные о местонахождении заданы как неопределенные.Я думаю, что это может быть потому, что они раскрывающийся список и текстовая область?но я не вижу, чтобы полностью понять, почему ошибка появляется.Кроме того, как бы я отправил переключатели в базу данных?понадобятся ли им конкретные значения?
Ниже приведена страница jobs.html
<?php
//allow the config
define('__CONFIG__', true);
//require the config
require_once "inc/config.php"; //possibly have to change the location
Page::ForceLogin();
?>
<!DOCTYPE html>
<html>
<head>
<!-- UIKit CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.24/css/uikit.min.css" />
<link rel="stylesheet" href="style.css">
<title>Login Page</title>
<base href="/"/>
<nav class="uk-navbar-container uk-margin" uk-navbar>
<div class="uk-navbar-left">
<a class="uk-navbar-item uk-logo" href="comp1687/index.php"><img src="/comp1687/jobswatchsmall.png" alt="sitelogo"></a>
<ul class="uk-navbar-nav">
<li>
<a href="comp1687/index.php">
<span class="uk-icon uk-margin-small-right" ></span>
<b>Home Page</b>
</a>
</li>
<li>
<a href="comp1687/jobs.php">
<span class="uk-icon uk-margin-small-right" ></span>
<b>Jobs</b>
</a>
</li>
</div>
<div class="uk-navbar-center">
<div class="uk-navbar-item">
<form action="javascript:void(0)">
<input class="uk-input uk-form-width-small" style="width:350px; border-radius: 10px; " type="text" placeholder="Input">
<button class="uk-button uk-button-default" style="border-radius: 10px;">Button</button>
</form>
</div>
</div>
<div class="uk-navbar-right">
<ul class="uk-navbar-nav">
<li>
<a href="comp1687/about.php">
<span class="uk-icon uk-margin-small-right" ></span>
<b>About Us</b>
</a>
</li>
<li>
<a href="comp1687/dashboard.php">
<span class="uk-icon uk-margin-small-right" ></span>
<b>Profile Page</b>
</a>
</li>
</div>
</nav>
</head>
<body>
<div class="uk-section uk-container">
<div class="uk-grid uk-child-width-1-3@s uk-child-width-1-1" uk-grid></div>
<h2><b><center>Jobs</center></b></h2>
<div style="border: 3px solid #ddd; border-radius: 10px; padding: 10px;">
<h4><center>Welcome to the job browsing section. You are able to browse the available jobs below, and if desired, you may post your own job!</center></h4>
<div class="jobspost" style="border: 3px solid #ddd; border-radius: 10px; padding: 10px;">
<h4><center><b>Post a job</b></center></h4>
<form class="uk-form-stacked js-jobs">
<fieldset class="uk-fieldset">
<div class="uk-margin">
<label class="uk-form-label" for="form-stacked-text"><b>Job title:</b></label>
<input id="jobTitle" class="uk-input" type="text" required placeholder="Insert the name of the job">
</div>
<div class="uk-margin">
<label class="uk-form-label" for="form-stacked-text"><b>Skills required:</b></label>
<input id="jobSkills" class="uk-input" type="text" required placeholder="Insert the skills needed for the job">
</div>
<div class="uk-margin">
<label class="uk-form-label" for="form-stacked-text"><b>Job description:</b></label>
<textarea id="jobDescription" class="uk-textarea" rows="5" required placeholder="Insert a description of the job"></textarea>
</div>
<div class="uk-margin">
<label class="uk-form-label" for="form-stacked-text"><b>Images (If necessary):</b></label>
<input id="jobImage" class="uk-button uk-button-default" type="file" name="jobImage" >
</div>
<div class="uk-margin">
<label class="uk-form-label" for="form-stacked-text"><b>Job location:</b></label>
<select id="jobLocation" required class="uk-select">
<option>-Select a region of london for the jobs location-</option>
<option>-------CENTRAL-------</option>
<option>Camden</option>
<option>City of London</option>
<option>Kensington and Chelsea</option>
</select>
</div>
<div class="uk-margin">
<label class="uk-form-label" for="form-stacked-text"><b>Job reward:</b></label>
<input id="jobReward" class="uk-input" required type="text" placeholder="Insert the amount of credits this job is worth">
</div>
<div class="uk-margin uk-grid-small uk-child-width-auto uk-grid">
<label class="uk-form-label" for="form-stacked-text"><b>Job status:</b></label>
<label><input id="jobStatus" class="uk-radio" type="radio" name="radio2" checked> Available</label>
<label><input id="jobStatus" class="uk-radio" type="radio" name="radio2"> Completed</label>
</div>
<center><button id="jobbtn" name="jobbtn" class="uk-button uk-button-default" type="submit"><b>SUBMIT JOB</b></button></center>
<br>
</fieldset>
</form>
</div>
<br>
<div class="jobsbrowse" style="border: 3px solid #ddd; border-radius: 10px; padding: 10px;">
<h4><center><b>Browse the jobs</b></center></h4>
</div>
</div>
</div>
<?php require_once "inc/footer.php"; ?> <!-- possibly have to change the location -->
</body>
</html>
Ниже приведен код ajax / jobs
<?php
//allow the config
define('__CONFIG__', true);
//require the config
require_once "../inc/config.php"; //possibly have to change the location
if($_SERVER['REQUEST_METHOD'] == 'POST') {
//Always return JSON format
//header('Content-Type: application/json');
$return = [];
$jobTitle = Filter::String($_POST['jobTitle']);
$jobSkills = Filter::String($_POST['jobSkills']);
$jobDescription = Filter::String($_POST['jobDescription']);
$jobLocation = Filter::String($_POST['jobLocation']);
$jobReward = Filter::String($_POST['jobReward']);
$jobStatus = Filter::String($_POST['jobStatus']);
// make sure the user adds a job.
$addJob = $con->prepare("INSERT INTO jobs(jobTitle, jobSkills, jobDescription, jobLocation, jobReward, jobStatus) VALUES(:jobTitle, :jobSkills, :jobDescription, :jobLocation, :jobReward, :jobStatus)");
$addJob->bindParam(':jobTitle', $jobTitle, PDO::PARAM_STR);
$addJob->bindParam(':jobSkills', $jobSkills, PDO::PARAM_STR);
$addJob->bindParam(':jobDescription', $jobDescription, PDO::PARAM_STR);
$addJob->bindParam(':jobLocation', $jobLocation, PDO::PARAM_STR);
$addJob->bindParam(':jobReward', $jobReward, PDO::PARAM_STR);
$addJob->bindParam(':jobStatus', $jobStatus, PDO::PARAM_STR);
$addJob->execute();
// return the proper information back to Javascript to redirect us.
echo json_encode($return, JSON_PRETTY_PRINT);
} else {
//Kill the script. Redirect the user.
exit('Invalid URL');
}
?>
Ниже приведен кодОтветственный за отправку JS.
.on("submit", "form.js-jobs", function(event) {
event.preventDefault();
var _form = $(this);
var _error = $(".js-error", _form);
var jobObj = {
jobTitle: $("input[id='jobTitle']", _form) .val(),
jobSkills: $("input[id='jobSkills']", _form) .val(),
jobDescription: $("input[id='jobDescription']", _form) .val(),
jobLocation: $("input[id='jobLocation']", _form) .val(),
jobReward: $("input[id='jobReward']", _form) .val(),
jobStatus: $("input[id='jobStatus']", _form) .val(),
};
if(jobObj.length < 1) {
_error
.text("Please fill in all fields.")
.show();
return false;
}
// Assuming the code gets this far, we can start the ajax process
_error.hide();
console.log(jobObj)
$.ajax({
type: 'POST',
url: 'comp1687/ajax/jobs.php', //possibly have to change the location
data: jobObj,
dataType: 'json',
async: true,
})
.done(function ajaxDone(data) {
// Whatever data is
if(data.redirect !== undefined) {
window.location.reload();
console.log('data');
} else if(data.error !== undefined) {
_error
.html(data.error)
.show();
console.log('data');
}
})
.fail(function ajaxFailed(e) {
//this failed
console.log(e);
})
.always(function ajaxAlwaysDoThis(data) {
//always do
console.log('Always');
})
return false;
})