0

What I want to do is have a page that collects a few pieces of information from the user and then calculates a result of a formula.

I do not want to store the information at all, and was thinking I may need to use the PHP Input type.

closed as too broad by Clive Mar 20 at 13:55

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I would more look into Drupal's Form API. A quickstart guide can be found here: drupal.org/node/751826 – Jimajamma Jul 22 '12 at 19:04
  • Why PHP ? Use JS to do all the math if you are not storing any of the results. – GoodSp33d Jul 22 '12 at 20:49
4

I see you've tagged this question with JavaScript, so it looks like you want to make a calculator using JavaScript.

To do this, you could make a custom module.

Create a module called calcform. Create calcform.js In your calcform.module you could create a custom block that has the calcform form.

You'll need to checkout: Creating modules | Block examples

function calcform_form(&$form, &$form_state){
  $form['number1'] = array(
    '#type'=>'textfield',
  );
  $form['number2'] = array(
    '#type'=>'textfield',
  );
  $form['calc_button'] = array(
    '#type'=>'button',
    '#value'=>'Calculate',
  );
  return $form;
}

Then in your JavaScript:

(function($){

  Drupal.calcform = {}

  Drupal.behaviors.calcform = {
    attach:function(){
      Drupal.calcform.bindEvents();
    }
  }

  Drupal.calcform.bindEvents = function(){

    $('#calc-button').click(function(e){
      // Prevent default button from submitting the form.
      e.preventDefault();
      // Do your magic here.
    });  

  }

}(jQuery));

This is all very pseudo-cody, but it's the general idea. You actually don't need to write ANY JavaScript. You could create a form submit function that does the calculations and prints out the result to the form. You can then use the $form['#ajax'] capabilities to do all the magic for you.

Drupal is amazing like that.

  • This is the type of information I was looking for! I assumed there would be some javascript involved, but I wasn't sure, and I had no idea how else to tag the question. Thank you. – Shane Grant Jul 22 '12 at 23:07
0

You can do this online calculator in Drupal in several ways:

Write from scratch

For this we use plain JavaScript and, if necessary, the Drupal API itself. We add the usual form with the required fields and then, using the data entered into them by the user, we calculate using JavaScript using the given formula. If you need to send calculations to email, then you need to use PHP with the standard function mail () or SMTP or any modules to send data to email. As you know, this method requires considerable knowledge in programming.

Ready Modules

Perhaps there are several ready-made modules that allow you to make a calculation on Drupal, for example, Web Form Calculator and the like. However, they will have to be considerably refined for a specific calculator to use on your website. Obviously, this refinement will require a significant amount of time and skill.

Online services

You can choose a ready-made online designer to create a calculator and add it to the pages of the site. For example, JsCalc or uCalc. JsCalc will require some development skills to use the code. But uCalc can be used by people who do not own programming at all or do not want to waste time on development.

Order the development of a calculator

And the simplest but not cheap way, of course, is a simple calculator order from web studios and freelancers. This method is for those who have a budget for it.

In any case, I hope these lines will help novice developers to figure out which tool to create a calculator for them to choose :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.