I have this form to update a record using PHP MySQL. I want to retrieve the value of the date column in a datepicker field. Is that possible? I try using $_REQUEST['date']
, but the result is empty. This is my form code:
<script type="text/javascript">
$(function(){
$('#date_4').datepicker({
dateFormat: 'yy-mm-dd'
});
});
</script>
<form enctype="multipart/form-data" id="fm" method="post" novalidate>
<div class="fitem">
<label>No:</label>
<input name="id" id="id" class="easyui-validatebox" size="50" required>
</div>
<div class="fitem">
<label>Date:</label>
<input id="date_4" name="date_3" class="easyui-validatebox" size="50">
</div>
<div class="fitem">
<label>From:</label>
<input id="from" name="from" class="easyui-validatebox" size="50" required>
</div>
<div class="fitem">
<label>Hal:</label>
<textarea name="hal" class="easyui-validatebox" cols="48" rows="5" required></textarea>
</div>
<div class="fitem">
<label>attachment:</label>
<input type="hidden" name="max_file_size" value="20000" />
<input name="userfile" type="file" />
</div>
</form>
You are using method="post" on your form, hence it'd be more correct to grab it from $_POST['date_3']. See the code below (sorry for the length, thought it'd be better to show the full thing)
<!doctype html>
<html lang="en">
<head>
<meta ncharset="utf-8"/>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<?php
if(isset($_POST['date_3'])){
echo $_POST['date_3'];
}
?>
<form enctype="multipart/form-data" id="fm" method="post" novalidate>
<div class="fitem">
<label>No:</label>
<input name="id" id="id" class="easyui-validatebox" size="50" required>
</div>
<div class="fitem">
<label>Date:</label>
<input id="date_4" name="date_3" class="easyui-validatebox" size="50">
</div>
<div class="fitem">
<label>From:</label>
<input id="from" name="from" class="easyui-validatebox" size="50" required>
</div>
<div class="fitem">
<label>Hal:</label>
<textarea name="hal" class="easyui-validatebox" cols="48" rows="5" required></textarea>
</div>
<div class="fitem">
<label>attachment:</label>
<input type="hidden" name="max_file_size" value="20000" />
<input name="userfile" type="file" />
</div>
<input type="submit" value="Go!">
</form>
<script type="text/javascript">
$(function(){
$('#date_4').datepicker({
dateFormat: 'yy-mm-dd'
});
});
</script>
</body>
</html>
Either way, it works fine for $_REQUEST too, since $REQUEST holds $_GET, $_POST and $_COOKIE (see this post about $_REQUEST vs $_GET and $_POST) You can replace the PHP code above with the following and it will still print your date, if you select one, once you submit it:
<?php
if(isset($_REQUEST['date_3'])){
echo $_REQUEST['date_3'];
}
?>