Page 1 of 1

Need urgent help. RE: Instant price quote form using PHP!

Posted: Fri Feb 19, 2010 4:51 pm
by khkit
Hey man,

Quick question for you. Okay first go here.

http://www.maaximumseduction.com/test.php


Here is what I am trying to do. This is sort of like an instant quote calculator for any sort of service. In this instance A moving company. You can get an instant quote.


You fill in the data and based on certain calculations, you get on the same page below a quantity or total dollar worth of the costs. So far I only have it adding up the data inputted into Total distance travel in KM and total weight of Boxes.


Here is the code for you to reference.

CODE:


html>
<body>

Get an online quote right now!

<form method="get">
Total distance to travel in KM: <input type="INT" name="distance1" /><br />
Total weight of the boxes in Kg: <input type="INT" name="weight1" /><br />


<input type="submit" name="submit" value="Submit me!" />
</form>



<?php
$first = $_GET['distance1'];
$second = $_GET['weight1'];
$answer = $first + $second;
$money=number_format($answer, 2);


echo "Your total cost is \n" ;

echo "\$", $money

?>




</body>
</html>



<table width="348" cellspacing="5" cellpadding="5">
<tr>
<td width="326" height="410" valign="top"><form method="get">
<table width="310" cellspacing="5" cellpadding="5">
<tr>
<td>Total distance to travel in kilometers:</td>
<td><input type="INT" name="distance2" /></td>
</tr>
<tr>
<td>Total weight of the boxes in kilograms: </td>
<td><input type="INT" name="weight1" /></td>
</tr>
<tr>
<td>Total number of rooms: </td>
<td><input type="INT" name="distance1" /></td>
</tr>
<tr>
<td>Total number of <br>
boxes </td>
<td><input type="INT" name="distance3" /></td>
</tr>
<tr>
<td>What sort of property do you have</td>
<td><select name="property[]" id="property1">
<option selected>Condo</option>
<option>House</option>
<option>Office</option>
</select></td>
</tr>
<tr>
<td>How many trips<br>
do you think the move will take </td>
<td><select name="tripa[]" id="trip">
<option value=1>1</option>
<option>2</option>
<option>3</option>
</select></td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="Submit me!" />
</p>
<p>








<?php
$first = $_GET['distance1'];
$second = $_GET['weight1'];
$third= $_GET['tripa[]'];




$answer = $first + $second + $third;
$money=number_format($answer, 2);


echo "Your total cost is \n" ;

echo "\$", $money





?>
</p>
<p>&nbsp;</p>
</form></td>
</tr>
</table>


Now here is what I am trying to do. I want to know how to take the multiple select list options and put that into a variable.

For instance, there are two list. options boxes in my form.

One for number of trips
and One for type of property.



I want first of all to add, just to test.

the number that is selected by the user in "trips" to $first and $second, but it doesn't add it.


Here is what I am doing. So my select name is "trips"
so I am storing that in a variable called $third= $_GET['trips'];
$third variable, it doesn't add.

I am just wondering how you take input from a multiple select part of a form
and store that in a variable as a number and use .I am assuming an IF/Then statement to store whatever option the user selected into a final variable that gets counted in the ultimate sum.


SO basically, it is for an instant price quote form.

You fill out the form which includes some list option elements and based on whatever option you select, the variable that stores this data is given the equivalent numerical value of that particular form list options or elements value.

and then added to the final sum.


Thanks




Omer

Re: Need urgent help. RE: Instant price quote form using PHP!

Posted: Fri Feb 19, 2010 5:41 pm
by Weiry
Firstly, <input> doesnt support the " type='INT' ", please change them to " type='text' "
For more about HTML Forms, visit W3Schools - HTML <input> Tag

Secondly, you need to double check your names for your second form. You are passing distance1 from the number of rooms rather than the distance...

Your php problem is when your trying to access the information that is inside the array's from the select boxes.
khkit wrote:$third= $_GET['tripa[]'];
Should be:

Code: Select all

$third= $_GET['tripa'];
And to access that variable, you need to refer to it as an array:

Code: Select all

print_r($third); print "<br/>";
print $third[0];

Re: Need urgent help. RE: Instant price quote form using PHP!

Posted: Sat Feb 20, 2010 10:29 am
by khkit
Hi thanks for your help. Well I got it to work


Here is the url where I have my instant quote form being developed

http://www.maaximumseduction.com/test.php


You can now input numbers into the first two textboxes and select a number from the list and it adds it correctly to make up the total sum.


Here is the code for your reference


<html>
<body>

Get an online quote right now!
HTML FORM

<form method="get">
Total distance to travel in KM: <input type="INT" name="distance1" /><br />
Total weight of the boxes in Kg: <input type="INT" name="weight1" /><br />




<select name="trip1" id="trip">
<option>1</option>
<option>2</option>
<option>3</option>
</select>

<input type="submit" name="submit" value="Submit me!" />

</form>



<?php
$first = $_GET['distance1'];
$second = $_GET['weight1'];
$third = $_GET['trip1'];


$answer = $first + $second +$third;
$money=number_format($answer, 2);


echo "Your total cost is \n" ;

echo "\$", $money

?>


Now here is what I want to do and perhaps need to use an IF/THEN conditional statement with an array to depending on what value from the multiple select drop down list is selected to add a specific total to the cost. Like if you pick 1, then the variable $third=30, if you select 2 then it is equal to 100 and so on.


Can you please tell me how I can set up this conditional statement and ultimately get the $third variable to have different values depending on what option is selected in the multi select drop down list.



Thanks


Omar