Answer the question
In order to leave comments, you need to log in
Why is the data sent by a Get request and not a post as I indicated?
The form
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Добавление акции");
?>
<form id="formPromo">
Название:<input name='name'/><br>
Дата:<input name='date' type ='date'/><br>
Описание:<textarea name='discription'></textarea><br>
Ссылка:<input name='addres'/><br>
Картинка:<input name='picture' type ='file'/><br>
<input value='Добавить' type='submit'>
</form>
<?php require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>
(function ($) {
jQuery(document).ready(function ($) {
$("#formPromo").submit(function () {
var form_data = $(this).serialize();
$.ajax({
type: "POST",
url: "/promo/edit/promo.php",
data: form_data,
success: function () {
alert('Форма успешно отправлена!');
}
});
return false;
});
});
})(jQuery);
<?php
$APPLICATION->SetTitle("Title");
if(isset($_POST['name'])&&$_POST['name']!="")
{
$name = htmlentities($_POST['name']);
//$date = htmlentities($_POST['date']);
//$discription = htmlentities($_POST['discription']);
//$addres = htmlentities($_POST['addres']);
//$picture = htmlentities($_POST['picture']);
if (CModule::IncludeModule('iblock')){
$el = new CIBlockElement;
$arProp["NAME"] = $name;
$arFields = array(
'NAME' => $fio."-".$mail,
'MODIFIED_BY' => $USER->GetID(),
'IBLOCK_ID' => 13,
'ACTIVE' => 'Y',
'PROPERTY_VALUES' => $arProp
);
$intOfferID = $el->Add($arFields);
}
}
?>
Answer the question
In order to leave comments, you need to log in
I'm assuming that when the "Add" button is clicked, the form is sent to the server before the JS is processed.
Alternatively, you can replace it with
Also
edit the handler:
$("#submit").click(function () {
var form_data = $("#formPromo").serialize();
$.ajax({
type: "POST",
url: "/promo/edit/promo.php",
data: form_data,
success: function () {
alert('Форма успешно отправлена!');
}
});
return false;
});
});
$(this).serialize(); returns a string. and data should have an object
try along with
(for versions below 1.9.0)
specify
(version added: 1.9.0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question