【发布时间】:2016-10-27 08:25:04
【问题描述】:
这是我在表单页面上的内容:
<form action = "/register-process" method = "post" id="form1">
<script type="text/javascript">
jQuery(document).ready(function($) {
$(document).on('focusout', '#dateenglish', function () {
var dateenglish = $(this).val();
$.ajax({
url: 'http://www.mountsinaiparks.org/digital-yahrzeit/wp-content/themes/yahrzeit-theme/getdate.php',
data: {
'dateenglish': dateenglish
},
success:function(data) {
// This outputs the result of the ajax request
$('#dateenglish').val(data);
},
error: function(errorThrown){
console.log(errorThrown);
}
});
});
});
</script>
<input id = "dateenglish" class="form_area" required name = "dateenglish" required type = "text" value="<?= $date; ?>" />
<input id = "datehebrew" class="form_area" required name = "datehebrew" required type = "text" value="<?= $date; ?>" />
</form>
这就是我在 getpage.php 中的内容:
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php' );
// Do the following if the form submits
if (isset($_REQUEST['dateenglish'])) {
$date = $_REQUEST['dateenglish'];
global $wpdb;
$stmt = "SELECT
heb_date,
greg_date
FROM calendar
WHERE greg_date = '".$date."'
OR heb_date = '".$date."'
";
$myrows = $wpdb->get_results($stmt);
// Not sure if its an array that is returned, but this will get the first value.
$row = current($myrows);
// Let's check which date is different
if ($date != $row['greg_date']) {
$date = $row['greg_date'];
} else {
$date = $row['heb_date'];
}
echo $date;
} else {
echo 'error';
}
?>
我要做的就是让表单从用户输入的“日历”表中查找日期数组,对照数据库进行检查,然后将第 2 行中的相应值返回到另一个字段中,AND VICE -VERSA。
I.E.有人输入一件事,它会检查,添加另一件事,然后它会保留。现在它不会留在场上。我错过了什么吗?
【问题讨论】:
标签: jquery sql json ajax wordpress