How to access POST before a form is submitted

Hi,

I want to access the values of 3 POST values and concatenate them. I am trying to do this:


<form action="" method="post" class="add" enctype="multipart/form-data">
            <table>
                <tr>
                    <td class="width"><label for="Year">Last access : </label></td>
                    <td>
                        <select name="day" id="day">
                            <?
                            for($i=1;$i<=31;$i++)
                            {
                                if($i == $day){
                                    echo "<option selected=\\"selected\\">$i</option>";
                                }else{
                                    echo "<option>$i</option>";
                                }
                            }
                            ?>
                        </select>
                        <select name="month" id="month">
                            <?
                            for($i=1;$i<=12;$i++)
                            {
                                if($i == $month){
                                    echo "<option selected=\\"selected\\">$i</option>";
                                }else{
                                    echo "<option>$i</option>";
                                }
                            }
                            ?>
                        </select>
                        <select name="year" id="year">
                            <?
                            for($i=2007;$i<=2030;$i++)
                            {
                                if($i == $year){
                                    echo "<option selected=\\"selected\\">$i</option>";
                                }else{
                                    echo "<option>$i</option>";
                                }
                            }
                            ?>
                        </select>
			<a href="#" onclick="cal.showCalendar('anchor'); return false;" title="cal.showCalendar('anchor'); return false;" name="anchor" id="anchor">select</a>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="hidden" name="WSlastaccess" value="<?=$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'] ." 00:00:00"?>"/>
                    <td><input type="submit" name="add" id="add" value="<?=isset($website->WSid) ? 'Edit' : 'Add'?>" /></td>
                </tr>
            </table>
        </form>

See this line:

<input type=“hidden” name=“WSlastaccess” value=“<?=$_POST[‘year’].‘-’.$_POST[‘month’].‘-’.$_POST[‘day’] .” 00:00:00"?>"/>

I want to pass the value of the date, but when i view source the value is blank…

How can i achieve this?

Thanks

Thanks, that worked perfectly. And it’s a long story why i want to do it this way. Basically i have build a class which handles all INSERTS and UPDATES and the values have to be the same as the rows in the database.

It’s worked perfectly up to now just got stuck no this problem :mad:

Thanks again for helping :smiley:

First of all, why do you want to concatenate before you submit the page since you can easily concatenate in the submitted page/script itself in the same way what you have done?

But if you really want to achieve the goal anyway, then you must use a JS code/function that is executed before the form is submitted like onsubmit even of form or onclick even of your submit button.


<script type="text/javascript">
    function transferDates(frm){
        frm.WSlastaccess.value = frm.year.value + '-' + frm.month.value + '-' + frm.day.value + ' 00:00:00';
        return true;
    }
</script>

<form onsubmit="return transferDates(this);" action="" method="post" class="add" enctype="multipart/form-data">

</form>

Doing this would be impossible without first submitting the form, an easy way i know of filling the values is with some simple JavaScript. See how this goes for you

<form action="" method="post" class="add" enctype="multipart/form-data">
            <table>
                <tr>
                    <td class="width"><label for="Year">Last access : </label></td>
                    <td>
                        <select name="day" id="day" onchange="parseValue('day',this.value)">
                            <?
                            for($i=1;$i<=31;$i++)
                            {
                                if($i == $day){
                                    echo "<option selected=\\"selected\\">$i</option>";
                                }else{
                                    echo "<option>$i</option>";
                                }
                            }
                            ?>
                        </select>
                        <select name="month" id="month" onchange="parseValue('month',this.value)">
                            <?
                            for($i=1;$i<=12;$i++)
                            {
                                if($i == $month){
                                    echo "<option selected=\\"selected\\">$i</option>";
                                }else{
                                    echo "<option>$i</option>";
                                }
                            }
                            ?>
                        </select>
                        <select name="year" id="year" onchange="parseValue('year',this.value)">
                            <?
                            for($i=2007;$i<=2030;$i++)
                            {
                                if($i == $year){
                                    echo "<option selected=\\"selected\\">$i</option>";
                                }else{
                                    echo "<option>$i</option>";
                                }
                            }
                            ?>
                        </select>
            <a href="#" onclick="cal.showCalendar('anchor'); return false;" title="cal.showCalendar('anchor'); return false;" name="anchor" id="anchor">select</a>
                    </td>
                </tr>
                <tr>
                    <td><input type="hidden" name="WSlastaccess" value="" />
                    <td><input type="submit" name="add" id="add" value="<?=isset($website->WSid) ? 'Edit' : 'Add'?>" /></td>
                </tr>
            </table>
        </form>
        
        <script type="text/javascript">
        function parseValue(method,option){
            var day = '', month = '', year = '';
            
            if (method == 'day'){
                day = option;
            } else if (method == 'month'){
                month = option;
            } else if (method == 'year'){
                year = option;
            }

            document.getElementById('WSlastaccess').value = year+'-'+month+'-'+day+' 00:00:00';
        }
        </script>