2

Truthfully, I haven't got a clue when it comes to PHP, but I can see the power of it, I just want to learn how to control it. I've got a three page booking form. Pages one to two are working, but two to three isn't working. Here's the PHP code from page two -

<?php

// Total Number of Nights Between Picked Dates

$days = (strtotime($_POST["checkoutdate"]) - strtotime($_POST["checkindate"])) / 86400 - 1;

// Extra Nightly Cost

define ("extranights", 80);
$addnights = (int)extranights * ($days - 4);

// Deposit Price Calculation

define("deposit", 370); 
$deposit = null;

if (isset($_POST["numberofpeople"])) {
$numberofpeople = intval($_POST["numberofpeople"]);
$deposit = ((int)deposit * $numberofpeople + $addnights) * 0.3;
}     

// Total Price Calculation

define("totalprice", 370);  
$result = null;

if (isset($_POST["numberofpeople"])) {
$numberofpeople = intval($_POST["numberofpeople"]);
$result = (int)totalprice * $numberofpeople + $addnights;
}     

?>

Then I've echoed the values of deposit and totalprice on the same page

<table>
<tr>
                <td width="573" height="30" align="right" valign="bottom" style="color:#0099FF;">( confirm reservation ) 30% Deposit :</td>
                <td width="158" align="left" valign="bottom" style="color:#0099FF; font-size:1.8em; line-height:23px;">&#8364;<?php echo $deposit; ?></td>
              </tr>

              <tr>
                <td height="30" align="right" valign="bottom" style="color:#0099FF;">Total Price :</td>
                <td align="left" valign="bottom" style="color:#0099FF; font-size:1.8em; line-height:23px;">&#8364;<?php echo $result; ?></td>
              </tr>
<td width="131" align="right" valign="middle" style="color:#000;"><input type="submit" name="submit" id="formbtn" value="CONTINUE" /></td>
</table>

What I've been agonising over is how to post the echoed values of deposit and totalprice on to a third page. If the solution/answer is extensive then I'll have to go back to the drawing board and start again, bit by bit. But this would finish the user side of the form. I'm not looking forward to the database stuff :(

3 Answers 3

3

Or use the intended:

<input type="hidden" name="deposit" value="$deposit" />
Sign up to request clarification or add additional context in comments.

Comments

0

include some hidden fields on page 2 with the computed values.

....
<input type="text" name="deposit" value="$deposit" style="display:none" />
...
<input type="text" name="result" value="$result" style="display:none" />

the values will then appear on the 3rd page in the $_POST array

2 Comments

YEEEEEESSSSSSSS!!!!! Thank you. I like the work around. It's working like a charm!
You really should use @AbraCadaver's answer though
0

This example combines php, js(AJAX) for dinamic form handling and sending via get all parameters, maybe it can save you some time. You shouldchange it for your needs though.

<table ALIGN="CENTER">
<table>
                    <?php  foreach ($chunkIt[1] as $k => $v){ ?>
                        <tr>    
                            <td width="150" height="" align="right" valign="middle" id='celda_interna_dealer'><strong><span id='texter1'><?php echo $v; ?></span></strong></td>

                        <?php if($arrD[$i] != 0){   ?>      
                            <td width="208" height="" align="left" valign="middle" id="celda_interna"><span id="texter1"><div id="ck-button"><label><input type="checkbox" name="<?php echo "status".$k; ?>" id="<?php echo "status".$k; ?>" value="<?php echo "status".$k; ?>" checked="yes"><span onclick="this.firstChild.data = this.firstChild.data == 'Des' ? 'Act' : 'Des'">Act</span></label></div></span></td>
                        <?php }else{ ?>
                            <td width="208" height="" align="left" valign="middle" id="celda_interna"><span id="texter1"><div id="ck-button"><label><input type="checkbox" name="<?php echo "status".$k; ?>"  id="<?php echo "status".$k; ?>" value="<?php echo "status".$k; ?>" ><span onclick="this.firstChild.data = this.firstChild.data == 'Des' ? 'Act' : 'Des'">Des</span></label></div></span></td> 
                        <?php } ?>
                        </tr>
                        <?php $i++; } ?>

                </table>
                </td>
                <td>
                <table ALIGN="CENTER">
                    <?php  foreach ($chunkIt[2] as $k => $v){ ?>
                        <tr>    <!-- ESTA PRIMERA LINEA ES SIEMPRE LA MISMA -->
                            <td width="150" height="" align="right" valign="middle" id='celda_interna_dealer'><strong><span id='texter1'><?php echo $v; ?></span></strong></td>

                        <?php if($arrD[$i] != 0){   ?>      
                            <td width="208" height="" align="left" valign="middle" id="celda_interna"><span id="texter1"><div id="ck-button"><label><input type="checkbox" name="<?php echo "status".$k; ?>" id="<?php echo "status".$k; ?>" value="<?php echo "status".$k; ?>" checked="yes"><span onclick="this.firstChild.data = this.firstChild.data == 'Des' ? 'Act' : 'Des'">Act</span></label></div></span></td>
                        <?php }else{ ?>
                            <td width="208" height="" align="left" valign="middle" id="celda_interna"><span id="texter1"><div id="ck-button"><label><input type="checkbox" name="<?php echo "status".$k; ?>"  id="<?php echo "status".$k; ?>" value="<?php echo "status".$k; ?>" ><span onclick="this.firstChild.data = this.firstChild.data == 'Des' ? 'Act' : 'Des'">Des</span></label></div></span></td> 
                        <?php } ?>
                        </tr>
                        <?php $i++; } ?>
                </table>
                </td>
                </tr>
                        <tr>
                            <td  colspan="3" align="center" valign="middle" id='celda_interna' height="31">
                                <input type="button" value="<?php echo $confirm_btn; ?>" onclick="Aj();"></input> 
                                <input type="hidden" name="status_count" id="status_count" value="<?php echo $i; ?>" > <!-- --> </input>
                            </td>
                        </tr>

            </table>

//CREATE FUNCTION TO SAVE UR DATA IN JS VARS AND DUMP IN DB

                                var laVar = null;
                                function Aj() {


                                    var i = 0,
                                        input;

                                    var ar = [];

                                    while (input = document.getElementsByTagName('input')[i++]) {

                                        if (input.id.match(/^status([0-9]+)$/)) {

                                            ar.push(input.id);

                                        }
                                    }


                                    var status_count_demo = document.getElementById('status_count').value;

                                    var status_count = status_count_demo - 1;


                                    i = 0;

                                    var ar3 = new Array();

                                    while (i <= status_count) {

                                        var campo = document.getElementById(ar[i]).checked;

                                        if (campo === true) {


                                            ar3[ar[i]] = 1;

                                        } else {

                                            ar3[ar[i]] = 0;

                                        }
                                        i++;
                                    }


                                    function url(data) {

                                        var ret = [];

                                        for (var d in data)


                                            ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));


                                        return ret.join("&");

                                    }


                                    if (window.ActivexObject) {


                                        laVar = new ActivexObject("Microsoft.XMLHTTP");

                                    } else if (window.XMLHttpRequest) {


                                        laVar = new XMLHttpRequest();

                                    } else alert("Tu navegador no acepta Ajax");

                                    laVar.open("GET", "inner_files/conf_confirm.php?" + url(ar3));


                                    laVar.onreadystatechange = cbFunc;

                                    laVar.send(null);

                                }



                                function cbFunc() {
                                    if (laVar.readyState == 4 && laVar.status == 200) {  alert('Success'); }

                                }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.