我有一个表单,我想发布到一个类,但无论何时,我点击提交,控制台都会返回GET
而不是POST
我的所有字段名称和值在此网址中http://rogerstracker.com/2/priority.php?yourName=&functionalArea=&publicationWeek=&otherCommunication=&LifeCycles%5B%5D=&priorityTitle=&IQLink=&IQliveDate=&nameOfKMSpecialist=&consideredPriority=&Content=&priorityRequest=Priority+Request&emp_id=&postPriorityRequest=Submit
这是我的班级
class Post_Form
{
private $db_connection = null;
private $lang = array();
public $errors = array();
public $messages = array();
public function __construct()
{
$this->lang = & $GLOBALS['_language'];
// if a POST request exist, call the insertNewPriorityRequest()
if (isset($_POST["postPriorityRequest"])) {
$this->insertNewPriorityRequest(currentDateTime(), $_POST["priorityRequest"], $_POST["yourName"], $_POST["emp_id"], $_POST["functionalArea"], $_POST["publicationWeek"], $_POST["otherCommunication"], $_POST["allAudiences"], $_POST["LifeCycles[]"], $_POST["priorityTitle"], $_POST["IQLink"], $_POST["IQliveDate"], $_POST["nameOfKMSpecialist"], $_POST["consideredPriority"], $_POST["Content"]);
}
}
// Checks if database connection
private function databaseConnection()
{
// connection already opened
if ($this->db_connection != null) {
return true;
} else {
// create a database connection, using the constants from config/config.php
try {
$this->db_connection = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME, DB_USER, DB_PASS);
return true;
// If an error is catched, database connection failed
} catch (PDOException $e) {
$this->errors[] = $this->lang['Database error'];
return false;
}
}
}
// Handles form posting process. Return possible errors, and insert new ticket in the database
private function insertNewPriorityRequest($currentDateTime, $priorityRequest, $yourName, $emp_id, $functionalArea, $publicationWeek, $otherCommunication, $allAudiences, $LifeCycles, $priorityTitle, $IQLink, $IQliveDate, $nameOfKMSpecialist, $consideredPriority, $Content)
{
// Check which life cycles are selected
if (isset($allAudiences)) {
$audiance = $allAudiences.implode(', ', $LifeCycles);
} else {
$audiance = implode(', ', $LifeCycles);
}
// Validate data
if (strlen($Content) > 300 || strlen($Content) < 1) {
$this->errors[] = $this->lang['Content too long'];
// If the above checks are okay
} else if ($this->databaseConnection()) {
// Write new ticket
$insert_ticket = $this->db_connection->prepare('INSERT INTO ccc_tickets (EMP_ID, `date`, submitter, priority, assigned, type) VALUES (:emp_id, :currentdate, :yourName, :priority, :assigned, :type);');
$insert_ticket->bindValue(':emp_id', $emp_id);
$insert_ticket->bindValue(':currentdate', $currentDateTime);
$insert_ticket->bindValue(':yourName', $yourName);
$insert_ticket->bindValue(':priority', $priority);
$insert_ticket->bindValue(':assigned', $assignedTo);
$insert_ticket->bindValue(':type', $priorityRequest);
$insert_ticket->execute();
// Return id of new ticket id
$ticket_results = $this->db_connection->lastInsertId();
// Write new priority request into database
$insert_priority_request = $this->db_connection->prepare('INSERT INTO ccc_priority_request (ticket_id, functionalArea, publicationWeek, otherCommunication, lifeCycles, priorityTitle, IQLink, IQliveDate, nameOfKMSpecialist, consideredPriority, Content) VALUES (:ticket_id, :functionalArea, :publicationWeek, :otherCommunication, :allAudiences, :LifeCycles, :priorityTitle, :IQLink, :IQliveDate, :nameOfKMSpecialist, :consideredPriority, :Content);');
$insert_priority_request->bindValue(':ticket_id', $ticket_results);
$insert_priority_request->bindValue(':functionalArea', $functionalArea);
$insert_priority_request->bindValue(':publicationWeek', $publicationWeek);
$insert_priority_request->bindValue(':otherCommunication', $otherCommunication);
$insert_priority_request->bindValue(':LifeCycles', $LifeCycles);
$insert_priority_request->bindValue(':priorityTitle', $priorityTitle);
$insert_priority_request->bindValue(':IQLink', $IQLink);
$insert_priority_request->bindValue(':IQliveDate', $IQliveDate);
$insert_priority_request->bindValue(':nameOfKMSpecialist', $nameOfKMSpecialist);
$insert_priority_request->bindValue(':consideredPriority', $consideredPriority);
$insert_priority_request->bindValue(':Content', $Content);
$insert_priority_request->execute();
// Return messages
if ($insert_priority_request) {
$this->messages[] = $this->lang['Success'];
$this->post_successful = true;
} else {
$this->errors[] = $this->lang['Error'];
}
}
}
}
我的priority.php
呼叫Post_Form
Calss
$submit_post_form = new Post_Form();
这是我的HTML标记:
<form action="priority.php" type="POST" name="priorityRequestForm">
[ . . . ] <!-- The form is too long and they're just input text fields -->
<input type="submit" name="postPriorityRequest" value="Submit">
</form>
答案 0 :(得分:6)
应该是method="POST"
,而不是type=
。