2

I have a quotation form where the user fills out the boxes, clicks submit and the isset function works to see if its set before returning a quote.

<?php
if (isset($_POST['submit'])) {
    $total = $_POST['ssize'] + $_POST['condition'] + $_POST['opticalDrive'];
    ?> Price is <?php echo $total;
}
?>

This quotation only appears after clicking the submit button. If the user wishes to accept the quote i also want a form to appear with that quote. But i cant figure out how to include the HTML form in with that PHP so make it appear with it after the submit button.

This is an example of my form:

<form method="post">
    First Name: <input type="text" name="fname" />
    Surname: <input type="text" name="sname" />
    E-Mail Address: <input type="text" name="email" />
    House Number: <input type="text" name="HouseNo" />
    Street Name: <input type="text" name="Street" />
    Town/City: <input type="text" name="towncity" />
    Post Code: <input type="text" name="Postcode" />
</form>

So how can I combine them both to appear at the same time after the submit button?

2 Answers 2

1

You just place your html within the IF clause. If I understood correctly your question..

    <?php  
    if (isset($_POST['submit']))
    {        
         $total = (int)$_POST['ssize'] + (int)$_POST['condition'] + (int)$_POST['opticalDrive'];
    ?>

    Price is : <?php echo $total;  ?>

    <form method="post" action="scriptforthisform.php">
    <fieldset>
    <legend></legend>
    First Name: <input type="text" name="fname" value=""/>
    Surname: <input type="text" name="sname" value="" />
    E-Mail Address: <input type="text" name="email" value=""/>
    House Number: <input type="text" name="HouseNo" value=""/>
    Street Name: <input type="text" name="Street" value=""/>
    Town/City: <input type="text" name="towncity" value=""/>
    Post Code: <input type="text" name="Postcode" value=""/>
    <input type="submit" value="send" name="submit_quote" />
    </fieldset>
    </form>

  <?php 
   } 
   ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thankyou very much both of you. This seems to have solved it Damien. Thankyou
1

It's not explicit in your question, but I think you're implying that the page submits to itself (I would include a blank action attribute just so there's no ambiguity if this is the case). Here's something you can do:

<?php
    if (isset($_POST['submit'])) {
        $total = $_POST['ssize'] + $_POST['condition'] + $_POST['opticalDrive'];
        echo('Price is ' . $total . '<br>');
        // Include markup for your form here
?>
      <form method="post" action = "action.php">
         First Name: <input type="text" name="fname" />
         Surname: <input type="text" name="sname" />
         E-Mail Address: <input type="text" name="email" />
         House Number: <input type="text" name="HouseNo" />
         Street Name: <input type="text" name="Street" />
         Town/City: <input type="text" name="towncity" />
         Post Code: <input type="text" name="Postcode" />
         <input type = 'submit' name = 'submit' value = 'Submit'/>
       </form>
    }
?>

An alternative would be to have the total calculated client side and add the total in with the form from JavaScript. This would require the visitor to have JavaScript enabled, which may be against your requirements.

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.