Jump to content

Some help with my calculation form?!


suess0r

Recommended Posts

OK, need some help with a calculation form and some error checking...

 

I have a basic 4 Radio Button Form, and 1 textbox to enter in the Word count.

<form action="quote.php" method="post" enctype="multipart/form-data" name="listForm" id="form1">

<input type="radio" name="document" value="book" />

<input type="radio" name="document" value="student" />

<input type="radio" name="document" value="biz" />

<input type="radio" name="document" value="personal" />

<input name="num-words" type="text" size="20" />

<input type="submit" name="Submit2" value="Generate Quote" /></form>

*Note: I want to be able to ensure that the textbox is filled with a number > 0, and that it's a number and not text. Then POST to my next page

 

--Now, when I check the document I want to multiple the (# of words) X (specific decimal), works sometimes and sometimes it just repeats it..

 

<?php

$doc = $_POST['document'];

          $words = $_POST['num-words'];

  if($doc = "book")

  $calc = $words * .005;

    if($doc = "student")

$calc = $words * .01;

    if($doc = "biz")

$calc = $words * .025;

if($doc = "personal")

$calc = $words * .03;

  echo $calc;

?>

 

*I need to save this value somehow to POST to my next page for an order page. So what would be the best way to do that if I'm sending it to 1 more page before a checkout? Thanks for all your help!

Link to comment
https://forums.phpfreaks.com/topic/50316-some-help-with-my-calculation-form/
Share on other sites

*Note: I want to be able to ensure that the textbox is filled with a number > 0, and that it's a number and not text. Then POST to my next page

 

doing it pre-submit is javascript

 

 

 

--Now, when I check the document I want to multiple the (# of words) X (specific decimal), works sometimes and sometimes it just repeats it..

 

you need to use == when comparing, not =

 

 

 

*I need to save this value somehow to POST to my next page for an order page. So what would be the best way to do that if I'm sending it to 1 more page before a checkout? Thanks for all your help!

 

throw it in a session

Thanks so much... I solved the calculation problem with the "==" vs the "=". Still working out the pre-submit javascript with a validate-number function... but I was hoping if you or someone else could shed a little more light on how I should "throw it in a session." Let me know if you know of another post, or related page that has to do with either of the 2 issues (pre-submit & session) I'd appreciate any help, thanks again.

verifying a number...

You could look through the chars and do charAt() for each of the characters, if the are < 0 or > 9 then throw an error?... just a thought, I'm no javascript whiz.

 

sessions...

http://www.php.net/manual/en/ref.session.php

 

sorry, I'm not up to posting long comments, it's late.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.