kingo_2k2 Posted February 1, 2010 Share Posted February 1, 2010 Hi guys, I need help a client of mine would like a call calculate that generates average savings depedning on the data input into the form. The following Code is For the First Page which contains the form. <?php function callcalc_form() { $form = array(); $text = '<p><img src="/files/landlinetomobile/images/bigcalculator_0.jpg" alt="Calculator" title="calculator" align="right" hspace="10px" vspace="10px" width="250" height="235" />Centralcom are dedicated to saving companies however large or small money on their calls to mobile numbers.<br/><br/></p> <p>Below can be found our call calculator which you can see the MINIMUM Centralcom could save your company on a monthly and annual basis.<br/><br/></p> <p>Simply enter the amount of minutes and costs you are being presently being charged and hit ‘calculate now’ to see the results.<br/><br/></p> <p>This information is readily obtained from your fixed line bills – if you have difficulties in obtaining this or understanding this from your current bills please contact us and our dedicated staff can assist you in attaining this information as well as offer you further information with no obligations.<br/><br/></p> <p>Please note that our calculator shows only the Minimum savings that can be achieved by choosing to have Centralcom help you in your call cost reductions.<br/><br/></p> <p><a href="/content/contact-us">Contact us</a> to see how much more we might be able to save too.</p>'; $form['text'] = array( '#type' => 'item', '#value' => $text, ); $form['minutes'] = array( '#type' => 'textfield', '#title' => t('Monthly Minutes'), '#decription' => t('Monthly minutes used calling mobiles in minutes'), '#size' => 10, ); $form['spend'] = array( '#type' => 'textfield', '#title' => t('Monthly Spend'), '#decription' => t('Monthly spend on calls to mobiles in pounds(£)'), '#size' => 10, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Calculate'), ); return $form; } function callcalc_form_validate($form_id, $form_values) { if (empty($form_values['minutes']) || !is_numeric($form_values['minutes'])) { form_set_error('minutes', t('Please enter a numerical value')); } if (empty($form_values['spend']) || !is_numeric($form_values['spend'])) { form_set_error('spend', t('Please enter a numerical value')); } } function callcalc_form_submit($form_id, $form_values) { $minutes = $form_values['minutes']; $spend = $form_values['spend']; //echo $minutes; //echo $spend; //First Total - Price per minute $ppm = $spend / $minutes; //echo $ppm; //Second Total - minus 0.05 from ppm $minus = 0.05; $second_total = $ppm - $minus; //echo $second_total; //Third Total - Monthly saving - second total * total minutes $third_total = $second_total * $minutes; if ($third_total < 0) { $third_total = 0; } //echo $third_total; //Fourth total - Annual saving - third total * 12 $fourth_total = $third_total * 12; //echo $fourth_total; } ?> The action for the form is ( <form action="callcalc2.php?'third=$third_total&fourth=$fourth_total" accept-charset="UTF-8" method="post" id="callcalc-form">) This then takes me to callcalc2.php on this page the only php i have is; <?php $third_total = $_GET['third']; ?> Then <?php echo '$third_total' ?> which only displays $third_total and not the calculated value, as you can tell I dont know a huge amount about PHP any help would be hugly welcome To see the code in action http://www.mking-designs.com/test/callcalc.php Link to comment https://forums.phpfreaks.com/topic/190588-transfering-data-from-a-form-to-another-page/ Share on other sites More sharing options...
PHP Monkeh Posted February 1, 2010 Share Posted February 1, 2010 Just replace: <?php echo '$third_total' ?> with <?php echo $third_total; ?> Though I don't really agree on what's being done on the first page (why wrap it in a function in the first place?) this should solve the error you're getting. Link to comment https://forums.phpfreaks.com/topic/190588-transfering-data-from-a-form-to-another-page/#findComment-1005204 Share on other sites More sharing options...
Omirion Posted February 1, 2010 Share Posted February 1, 2010 You're POST-ing the vars. And on your process form you are using the $_GET. Use $_POST Link to comment https://forums.phpfreaks.com/topic/190588-transfering-data-from-a-form-to-another-page/#findComment-1005205 Share on other sites More sharing options...
kingo_2k2 Posted February 1, 2010 Author Share Posted February 1, 2010 I have added both and now nothing shows on the second page, the coding seems wired to me also was sent by the client from his old site which I belive was drupal. I was orginally sent this code which seemed to be using only 1 page to generate the data, as I have never used this type of code before I tried to make the user enter the details into the form and transfer the working out onto another page. function callcalc_form() { $form = array(); $text = '<p><img src="/files/landlinetomobile/images/bigcalculator_0.jpg" alt="Calculator" title="calculator" align="right" hspace="10px" vspace="10px" width="250" height="235" />Centralcom are dedicated to saving companies however large or small money on their calls to mobile numbers.<br/><br/></p> <p>Below can be found our call calculator which you can see the MINIMUM Centralcom could save your company on a monthly and annual basis.<br/><br/></p> <p>Simply enter the amount of minutes and costs you are being presently being charged and hit ‘calculate now’ to see the results.<br/><br/></p> <p>This information is readily obtained from your fixed line bills – if you have difficulties in obtaining this or understanding this from your current bills please contact us and our dedicated staff can assist you in attaining this information as well as offer you further information with no obligations.<br/><br/></p> <p>Please note that our calculator shows only the Minimum savings that can be achieved by choosing to have Centralcom help you in your call cost reductions.<br/><br/></p> <p><a href="/content/contact-us">Contact us</a> to see how much more we might be able to save too.</p>'; $form['text'] = array( '#type' => 'item', '#value' => $text, ); $form['minutes'] = array( '#type' => 'textfield', '#title' => t('Monthly Minutes'), '#decription' => t('Monthly minutes used calling mobiles in minutes'), '#size' => 10, ); $form['spend'] = array( '#type' => 'textfield', '#title' => t('Monthly Spend'), '#decription' => t('Monthly spend on calls to mobiles in pounds(£)'), '#size' => 10, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Calculate'), ); return $form; } function callcalc_form_validate($form_id, $form_values) { if (empty($form_values['minutes']) || !is_numeric($form_values['minutes'])) { form_set_error('minutes', t('Please enter a numerical value')); } if (empty($form_values['spend']) || !is_numeric($form_values['spend'])) { form_set_error('spend', t('Please enter a numerical value')); } } function callcalc_form_submit($form_id, $form_values) { //I ALSO REMOVED THIS $minutes = $form_values['minutes']; $spend = $form_values['spend']; //echo $minutes; //echo $spend; //First Total - Price per minute $ppm = $spend / $minutes; //echo $ppm; //Second Total - minus 0.05 from ppm $minus = 0.05; $second_total = $ppm - $minus; //echo $second_total; //Third Total - Monthly saving - second total * total minutes $third_total = $second_total * $minutes; if ($third_total < 0) { $third_total = 0; } //echo $third_total; //Fourth total - Annual saving - third total * 12 $fourth_total = $third_total * 12; //echo $fourth_total; drupal_goto('callcalc/saving', 'third='.$third_total.'&fourth='.$fourth_total); //I REMOVED THIS } function callcalc_saving() { //O $output = ''; $output .= '<img src="/files/landlinetomobile/images/bigcalculator_0.png" alt="Calculator" title="calculator" align="right" hspace="10px" vspace="10px" width="250" height="235" /><p>Please note that below shows only the Minimum savings that can be achieved by choosing to have Centralcom help you in your call cost reductions.</p> Contact us to see how much more we might be able to save too.'; $output .= '<div class="monthly"><h3>Monthly Saving</h3><h4>£'.$_GET['third'].'</h4></div>'; $output = '<div class="annual"><h3>Annual Saving</h3><h4>£'.$_GET['fourth'].'</h4></div>'; return $output; } This code works fine on his old site but could not tie into his new revamped site which is basic html and css his old site is http://www.landlinetomobile.com/callcalc Link to comment https://forums.phpfreaks.com/topic/190588-transfering-data-from-a-form-to-another-page/#findComment-1005215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.