Dynamic Form
Hi i was thinking how can we make a form where values are added in each form fields.
Its just like giving visitor a quotation or so depending upon options choosen.
Multiple form fields will be present.
Regards
Hi i was thinking how can we make a form where values are added in each form fields.
Its just like giving visitor a quotation or so depending upon options choosen.
Multiple form fields will be present.
Regards
you would need to have code the functionality to process the form input.
for example, if you have 2 form fields named element1 and element2. and each of these takes a numeric input, you can do simple math using the post:
<?php echo($_POST['element1'] + $_POST['element2']); ?>
<?php echo($_POST['element1'] + $_POST['element2']); ?>
this is my current form:
<form id="form1" name="form1" method="post" action="">
<p>
<label for="element1"></label>
x:
<input type="number" name="element1" id="element1" />
<br />
y:
<label for="element2"></label>
<input type="number" name="element2" id="element2" />
</p>
<p><strong>x+y=z</strong></p>
<p>z: <?php echo($_POST['element1'] + $_POST['element2']); ?>
</p>
</form>
i get errors as such:
Notice: Undefined index: element1 in /Applications/XAMPP/xamppfiles/htdocs/esskaybee/test.php on line 21
Notice: Undefined index: element2 in /Applications/XAMPP/xamppfiles/htdocs/esskaybee/test.php on line 21
0
line 21 codes: <p>z: <?php echo($_POST['element1'] + $_POST['element2']); ?>
you have to submit the form
you don't have a submit button in your form, so no way to submit it. you will need to add a submit button
you can add an if statement around the echo so it only shows when the form is submitted:
<?php if($_SERVER['REQUEST_METHOD'] == "POST") { ?>
<p>z: <?php echo($_POST['element1'] + $_POST['element2']); ?>
<?php } ?>
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.