Jump to content

Recommended Posts

Hey guys, I am reworking some code that somebody else wrote.  It basically gets time for an order.  However, I am suppose to add 15 minute intervals onto the form, and I have no clue how to process this correctly with what he has already written.  Here is the form:

<script type="text/javascript">
function toggleTimeSelects() {
  orderforsel = document.getElementById('order_for');
  timesel = document.getElementById('time');
  ampmsel = document.getElementById('ampm');
  if (orderforsel.value == "now") {
    timesel.disabled = true;
    ampmsel.disabled = true;
  } else if (orderforsel.value == '') {
    timesel.disabled = true;
    ampmsel.disabled = true; 
  } else {
    timesel.disabled = false;
    ampmsel.disabled = false;
  }
}
</script>

<select name="order_for" id="order_for" onchange="javascript:toggleTimeSelects()">
	<option value="now">Now</option>
	<option value="today">Today at:</option>
	<option value="tomorrow">Tomorrow at:</option>
</select>
<select name="time" id="time" disabled>
	<?php for ( $counter = 1; $counter <= 12; $counter += 1) { ?>
	<option value="<?php echo $counter; ?>"><?php echo $counter; ?></option>
	<?php } ?>
</select>
<select name="ampm" id="ampm" disabled>
	<option value="am">AM</option>
	<option value="pm">PM</option>
</select>

 

Here is the code that processes the form:

$order_for = $_POST['order_for'];
$time = $_POST['time'];
$ampm = $_POST['ampm'];

if ($order_for == 'now') {
  $forDate = date('Y-m-d H:i:s');
} else if ($order_for == 'today') {
  $forDate = date('Y-m-d',time() + 60*60).' '.($ampm == 'am' ? str_pad($time,2,'0',STR_PAD_LEFT) : ($time + 12)).':00:00';
} else {
  $forDate = date('Y-m-d',time() + 12*60*60).' '.($ampm == 'am' ? str_pad($time,2,'0',STR_PAD_LEFT) : ($time + 12)).':00:00';
}

Link to comment
https://forums.phpfreaks.com/topic/99374-help-with-time/
Share on other sites

Okay this is soo very untested

 

<select name="time" id="time" disabled>
	<?php for ( $counter = 1; $counter <= 12; $counter += 1) { ?>
	<option value="<?php echo $counter; ?>"><?php echo $counter; ?></option>
	<?php } ?>
</select>

<!-- Add -->
<select name="mins" id="mins" disabled>
	<?php for ( $counter = 0; $counter <= 45; $counter += 15) { ?>
	<option value="<?php echo $counter; ?>"><?php echo $counter; ?></option>
	<?php } ?>
</select>
<!-- done adding -->

<select name="ampm" id="ampm" disabled>
	<option value="am">AM</option>
	<option value="pm">PM</option>
</select>

 

$order_for = $_POST['order_for'];
$time = $_POST['time'];
$min = $_POST['mins']; //Add
$ampm = $_POST['ampm'];

if ($order_for == 'now') {
  $forDate = date('Y-m-d H:i:s');
} else if ($order_for == 'today') {
  $forDate = date('Y-m-d',time() + (60+$min)*60).' '.($ampm == 'am' ? str_pad($time,2,'0',STR_PAD_LEFT) : ($time + 12)).':$min:00'; //Edit
} else {
  $forDate = date('Y-m-d',time() + 12*(60+$min)*60).' '.($ampm == 'am' ? str_pad($time,2,'0',STR_PAD_LEFT) : ($time + 12)).':$min:00'; //Edit
}

 

Link to comment
https://forums.phpfreaks.com/topic/99374-help-with-time/#findComment-508467
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.