Home > Net >  Calling POST data from a PHP file
Calling POST data from a PHP file

Time:12-06

I have 3 php files and I want to get the month from form1.php for form3.php but the thing is, it needs to be processed in form2.php as well, how can I just get the month from form1 and display it in form3?

form1.php

<form action="form2.php" method="post">
        <div class="form-title">
            <p class="display-6">Salary Calculator (Part 1)</p>
        </div>

        <div class="form-subtitle">
            <p>Employee Information</p>
        </div>

        <div class="form-row">
            <div class="form-row-child">
                <label for="inputPlaceholder4">Employee Name</label>
                <select class="form-select" aria-label="Default select example" name="displayName" id="displayName">
                    <option selected>Select Employee</option>
                    <?php while($row = $result->fetch_assoc()) { ?>
                    <option value="<?php echo $row['displayName']; ?>"><?= $row["displayName"] ?></option>
                    <?php }; ?>
                </select>
            </div>
            
            <div class="form-row-child">
                <label for="inputPlaceholder4">Month</label>
                    <select class="form-select" aria-label="Default select example" name="month" id="month">
                    <option selected disabled>Select Month</option>
                    <option value="January">January</option>
                    <option value="Febuary">Febuary</option>
                    <option value="March">March</option>
                    <option value="April">April</option>
                    <option value="May">May</option>
                    <option value="June">June</option>
                    <option value="July">July</option>
                    <option value="August">August</option>
                    <option value="September">September</option>
                    <option value="October">October</option>
                    <option value="November">November</option>
                    <option value="December">December</option>
                </select>
            </div>
           
        </div>
        <div class="form-row">
            <div class="form-row-child">
                <input type="submit" class="btn btn-danger form1-btn" value="Proceed">
            </div>
            <div class="form-row-child">

            </div>
        </div>
    </form>

form2.php

<form action="form3.php" method="post">
        <div class="form-title">
            <p class="display-6">Salary Calculator (Part 2)</p>
        </div>

        <div class="half-form">
            <div class="half-form-left">
            <div class="half-form-subtitle">
                     <p>Holidays</p>
                </div>
                <div class="half-form-child">
                    <label for="inputPlaceholder3">Regular (Per day)</label>
                    <select class="form-select" aria-label="Default select example" name="holidayReg" id="holidayReg">
                    <?php foreach ($regHolidays as $value) { ?>
                        <option value="<?php echo $value; ?>"><?= $value ?></option>
                    <?php }; ?>
                    </select>
                </div>
                <div class="half-form-child">
                    <label for="inputPlaceholder3">Special (Per day)</label>
                    <select class="form-select" aria-label="Default select example" name="holidaySpec" id="holidaySpec">
                    <?php foreach ($specHolidays as $value) { ?>
                        <option value="<?php echo $value; ?>"><?= $value ?></option>
                    <?php }; ?>

                    </select>
                </div>
            </div>
            <div class="half-form-right">
                <div class="half-form-subtitle">
                     <p>Overtime</p>
                </div>
                <div class="half-form-child">
                    <label for="inputPlaceholder3">Normal (Per hour)</label>
                    <input type="Placeholder" class="form-control" id="overtimeHoursNormal" placeholder="Placeholder" name="overtimeHoursNormal">
                </div>
                <div class="half-form-child">
                    <label for="inputPlaceholder3">Rest Day (Per hour)</label>
                    <input type="Placeholder" class="form-control" id="overtimeHoursSpecial" placeholder="Placeholder" name="overtimeHoursSpecial">
                </div>
            </div>
        </div>
        <div class="half-form">
            <div class="half-form-left">
                <div class="half-form-subtitle">
                     <p>Absences</p>
                </div>
                <div class="half-form-child">
                    <label for="inputPlaceholder3">Day/s absent</label>
                    <input type="Placeholder" class="form-control" id="absences" placeholder="Placeholder" name="absences">
                </div>
            </div>
            <div class="half-form-right">
                <input type="Placeholder" class="form-control" id="basePay"  name="basePay" style="display: none;" value="<?php echo $vagueEmployee->getBasePay(); ?>">
                <input type="Placeholder" class="form-control" id="workingHours"  name="workingHours" style="display: none;" value="<?php echo $vagueEmployee->getWorkingHours(); ?>">
                <input type="Placeholder" class="form-control" id="salaryPerHour"  name="salaryPerHour" style="display: none;" value="<?php echo $salaryPerHour; ?>">
                <input type="Placeholder" class="form-control" id="payFor13thMonth"  name="payFor13thMonth" style="display: none;" value="<?php echo $payFor13thMonth; ?>">

            </div>
        </div>
        <div class="form-row">
            <div class="form-row-child">
                <input type="submit" class="btn btn-danger form1-btn" value="Proceed">
            </div>
            <div class="form-row-child">

            </div>
        </div>
    </form>

form3.php

<main class="main">
        <div class="form-title">
            <p class="display-6">Employee Salary</p>
        </div>

        <div class="">
            <p>Pay after additions: Php <?php echo $payAfterAdditions; ?></p>
            <p>Deductions</p>
            <p>Philhealth: Php <?php echo $philhealth; ?></p>
            <p>SSS: Php <?php echo $sss; ?></p>
            <p>Total deductions: Php <?php echo $totalDeductions; ?></p>
            <p>Taxable Salary: Php <?php echo $taxableSalary; ?></p>
            <p>Final Salary: Php <?php echo $finalTax; ?></p>
            <!-- lalabas lang kapag december -->
            <p>13 month pay: </p> 
            <p> <?php echo $totalAbsences; ?></p>
            <p> <?php echo $basePay; ?></p>
        </div>
    </main>

CodePudding user response:

In form 2

Add the following field inside the form

<input type=hidden name=month value="<?php echo $_POST["month"]; ?>">

Then in form 3, you can use $_POST["month"] to access the month value.

  • Related