Page 1 of 1

Change posted variable

Posted: Fri May 18, 2007 6:03 pm
by bob_the _builder
Hi,

I have a few select boxes to collect the chosen time via post:

Code: Select all

<select name="hour"> 
    <option value="1">1</option> <option value="2">2</option>
    <option value="3">3</option> <option value="4">4</option>
    <option value="5">5</option> <option value="6">6</option>
    <option value="7">7</option> <option value="8">8</option>
    <option value="9">9</option> <option value="10">10</option>
    <option value="11">11</option> <option value="12">12</option>
    </select>
	<select name="minute">
	<option value="00">00</option> 
    <option value="10">10</option>
    <option value="20">20</option>
    <option value="30">30</option>
    <option value="40">40</option>
    <option value="50">50</option>
    </select>
	<select name="ampm"> 
    <option value="am">Am</option>
    <option value="pm">Pm</option>
    </select>
Once the form is posted, if pm is selected I need to so it changes the posted hour value to 24 hour time:

example

if 1 is selected make it 13
if 2 is selected make it 14
if 3 is selected make it 15

etc etc

Cheers

etc etc

Posted: Fri May 18, 2007 6:05 pm
by RobertGonzalez
date() and strtotime()

Posted: Fri May 18, 2007 6:13 pm
by bob_the _builder
Hi,

Wouldnt it be easyer using maybe an array with str_replace if (isset($_POST['pm'])) ?


Thanks

Posted: Fri May 18, 2007 6:15 pm
by RobertGonzalez
You can. But if you were going to go that route you wouldn't have asked the question to begin because you would have tried that first.

Posted: Fri May 18, 2007 6:18 pm
by bob_the _builder
I have been playing with it, but havnt managed to make it work .. It seemed pluasable to me.

Thanks

Posted: Fri May 18, 2007 6:24 pm
by RobertGonzalez
Another thing can do is:

Code: Select all

<?php
$hour = !empty($_POST['hour']) ? $_POST['hour'] : 0;
if (!empty($_POST['ampm']) && $_POST['ampm'] == 'pm')
{
   $hour = $_POST['hour'] + 12;
}
?>

Posted: Fri May 18, 2007 6:30 pm
by bob_the _builder
Ahh of course, I didnt think about + 12.

Thanks