从请求中获取 POST 参数
Getting POST parameter from Request
我正在使用 Symfony4,我正在尝试从请求中获取 POST 参数。使用:
$request = Request::createFromGlobals();
$email = $request->request->get('email');
给我 null 但如果我这样做:
$request = Request::createFromGlobals();
var_dump($request->request->all());
我可以看到电子邮件参数已设置并且有一些值。
我的问题是:如何获取该参数值?
我post这里有一段我的代码:
/**
* @Route("/prenota/appuntamento/salva", name="app_habiter_calendario_save", methods={"POST"})
*/
public function salvaPrenotazione(ValidatorInterface $validator){
$request = Request::createFromGlobals();
$entityManager = $this->getDoctrine()->getManager();
$prenotazioni = new Prenotazioni();
$clienti = new Clienti();
$email = $request->request->get('email');
[...]
}
的截图
$request = Request::createFromGlobals();
var_dump($request->request->all());
请求由AJAX使用此功能发出。这可能是问题的原因吗?:
function sendMailAjax(form, method, url, outputElement){
let formData = new FormData(form);
$.ajax({
method: method,
url: url,
data: formData,
processData: false,
}).done(function (result) {
if(result.message === true) {
outputElement.css('color', 'green');
outputElement.text('Inviato');
}else {
outputElement.css('color', 'red');
outputElement.text('Errore');
}
});
}
在您的 AJAX 调用中,更改
let formData = new FormData(form);
$.ajax({
method: method,
url: url,
data: formData,
至:
let formData = $("form").serialize();
$.ajax({
method: method,
url: url,
data: formData,
我正在使用 Symfony4,我正在尝试从请求中获取 POST 参数。使用:
$request = Request::createFromGlobals();
$email = $request->request->get('email');
给我 null 但如果我这样做:
$request = Request::createFromGlobals();
var_dump($request->request->all());
我可以看到电子邮件参数已设置并且有一些值。 我的问题是:如何获取该参数值?
我post这里有一段我的代码:
/**
* @Route("/prenota/appuntamento/salva", name="app_habiter_calendario_save", methods={"POST"})
*/
public function salvaPrenotazione(ValidatorInterface $validator){
$request = Request::createFromGlobals();
$entityManager = $this->getDoctrine()->getManager();
$prenotazioni = new Prenotazioni();
$clienti = new Clienti();
$email = $request->request->get('email');
[...]
}
的截图
$request = Request::createFromGlobals();
var_dump($request->request->all());
请求由AJAX使用此功能发出。这可能是问题的原因吗?:
function sendMailAjax(form, method, url, outputElement){
let formData = new FormData(form);
$.ajax({
method: method,
url: url,
data: formData,
processData: false,
}).done(function (result) {
if(result.message === true) {
outputElement.css('color', 'green');
outputElement.text('Inviato');
}else {
outputElement.css('color', 'red');
outputElement.text('Errore');
}
});
}
在您的 AJAX 调用中,更改
let formData = new FormData(form);
$.ajax({
method: method,
url: url,
data: formData,
至:
let formData = $("form").serialize();
$.ajax({
method: method,
url: url,
data: formData,