在select下拉列表中对用户输入进行消毒,而在哪里端点。
当通过jQuery Ajax发布输入到另一个脚本以最终使用Curl将帖子请求发送到端点时,我将如何从选择的下拉列表中清除用户输入?在这种情况下,urlencode是否足够,因为我没有直接将其插入任何数据库,因此,我将这些数据发送到的端点显然会插入数据库中,但它是第三方app app
view.php
function edit_data_title() {
var lead_id = $("#LeadID").val();
var title = $(".title option:selected").val();
var agent_full_name = $("#agent_full_name").val();
if (confirm('Are you sure you want to update the Title of this lead?')) {
$.ajax({
url: "endpoint.php",
method: "POST",
data: {
lead_id: lead_id,
title: title,
agent_full_name: agent_full_name
},
dataType: "text",
success: function(data) {
//alert(data);
$('#title_readonly').hide();
$('#title_cancel').hide();
$('#title_edit_input').hide();
$('#title_edit_button').show();
$("#update_lead_title_result").html(data);
$('#update_lead_title_result').show();
$('#title').prop('selectedIndex', 0);
}
});
} else {
alert('Lead title update cancelled');
$('#title').prop('selectedIndex', 0);
}
}
<select name="title" id="title" class="title" onchange="edit_data_title();">
<option value="">Select an option</option>
<option value="Dr.">Dr.</option>
<option value="Hon.">Hon.</option>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
<option value="Prof.">Prof.</option>
<option value="Rev.">Rev.</option>
<option value="Other">Other</option>
</select>
endpoint.php
$title = $_POST['title'];
$curl_url = "https://endpoint101.com?title=$title";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $curl_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$curl_result = curl_exec($ch);
$curl_info = curl_getinfo($ch);
$curl_info = json_encode($curl_info);
curl_close($ch);
How would I go about sanitizing user input from my select drop-downs, when posting the input via Jquery AJAX to another script to finally sending a post request to an endpoint using curl? Would urlencode in this case be sufficient as I am not inserting this into any database directly, well the endpoint I am sending this data to will obviously insert into a database but its a 3rd party app
view.php
function edit_data_title() {
var lead_id = $("#LeadID").val();
var title = $(".title option:selected").val();
var agent_full_name = $("#agent_full_name").val();
if (confirm('Are you sure you want to update the Title of this lead?')) {
$.ajax({
url: "endpoint.php",
method: "POST",
data: {
lead_id: lead_id,
title: title,
agent_full_name: agent_full_name
},
dataType: "text",
success: function(data) {
//alert(data);
$('#title_readonly').hide();
$('#title_cancel').hide();
$('#title_edit_input').hide();
$('#title_edit_button').show();
$("#update_lead_title_result").html(data);
$('#update_lead_title_result').show();
$('#title').prop('selectedIndex', 0);
}
});
} else {
alert('Lead title update cancelled');
$('#title').prop('selectedIndex', 0);
}
}
<select name="title" id="title" class="title" onchange="edit_data_title();">
<option value="">Select an option</option>
<option value="Dr.">Dr.</option>
<option value="Hon.">Hon.</option>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
<option value="Prof.">Prof.</option>
<option value="Rev.">Rev.</option>
<option value="Other">Other</option>
</select>
endpoint.php
$title = $_POST['title'];
$curl_url = "https://endpoint101.com?title=$title";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $curl_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$curl_result = curl_exec($ch);
$curl_info = curl_getinfo($ch);
$curl_info = json_encode($curl_info);
curl_close($ch);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
$ title
值匹配可用的选项之一,则应检查服务器端。这是我从问题中给出的输入中推测的唯一条件。
https://www.php.net/manual/manual/en/function。 in-array.php
You should check server side if the
$title
value matches one of the options available.That's the only condition I could speculate from the input given in your question.
https://www.php.net/manual/en/function.in-array.php