Hi all,

I'm very very new to Drupal, and am still wrestling with it, so my question will seem pretty basic to most. Anyhow, the background is:

I'm creating a website for an air conditioner reseller who wants a user to be able to input the dimensions of a room in order to display a results page with suitable air conditioners for that particular size room. I'm yet to be provided with the actual equation to work out the results, but I'm just after a guide on how to get the task done.

I'm so green, that I'm not even sure of the best way to create the form, let alone the more difficult function of what I'm trying to achieve, so some guidance would be really appreciated. Is the best way to code up the form myself (and where would I go from there to implement it)? Or is there a module out there that will do all the leg work for me? I'm very competent with design, html, and css, but as mentioned Drupal and PHP is totally new to me and is causing me some headaches so I figure I should ask the pros!

Thanks guys/gals.

Comments

yasir farooqui’s picture

Hi

Try using "webform" module for building your own custom forms. This module will provide you an easy interface to create forms and an option to process the data with your own logic on form submission.

http://drupal.org/project/webform

Yzzi’s picture

Thanks Yasir.

That module is really helpful for creating the form itself, so thank you. If anyone can help out with the logic needed to calculate the users input, that would be awesome.

Thanks!

JohnnyMoney’s picture

Can you use some php to do this?
Don't know how the form you are using works as I haven't installed it yet, but I suppose if must have some variables that contain the data the user inputs. if that is so, then one can process those with a php script that could generate a link to the required destination page depending on the values received from the form.

yasir farooqui’s picture

Hi
You can obviously process the data submitted by the form that you created using web form module. There are two ways to process the data. In first one edit the form, go to Advance options >> Additional processing , and write your php code here to process the data. Webform provide you with two variables '$form_id and $form_values' to process the data.

If you are more comfortable with processing the post data, then use the other way. Edit webform , go to 'Confirmation message or redirect URL' , here you can mention an internal url as well as an external one. Now go to 'Advance options' and check 'Redirect POST Values'. Webform will send the post data to the url you mentioned, you process this data there.

For example you mentioned "internal:node/1" (assuming that you created a page in drupal whose node id is 1). Now go to node/1/edit and write your php code here. Let's suppose your webform contain two fields one is 'Length' and the other is 'Width'. Now on node/1

        $length = $_POST['submitted']['length'];
        $width = $_POST['submitted']['width'];
        $area = $length x $width x 337           //depends upon your formula
        switch($area) {
                 case '...'
        }
Yzzi’s picture

Thanks again Yasir!

You've been a big help. I will try to do it with your instructions, and will let you know what happens.

EDIT: Also thank you Johnny!

leon85321’s picture

Hi YASIR,

Can you comfirm if this code is working with current drupal 6.8 and webform 6.x-2.3?

I can not get it to work on my site...

I have tried use this code to view all the $_POST variables and they all appear to show up.

if ($_POST) {
    echo '<pre>';
    echo htmlspecialchars(print_r($_POST, true));
    echo '</pre>';
}

But when I tried using your code (with my array names) to echo the variables, they do not show the variables.

Thank you,

Leon

yasir farooqui’s picture

The code that I referred in my previous post seems to be working in drupal 5 only because in drupal 6 there is no option "Redirect post data" to be selected.

But what you can still do is to use the other way that I mentioned in the similar post. Or if you really want to be redirected to some page and process your data there then you can do this:

In "Confirmation message or redirect URL:" give the page that you want to do the processing on, say "internal:node/1".

Then under Webform advanced settings >> Additional Processing write this

<?php
  $_SESSION['mysubmit']['data'] = $_POST;
  return 'node/1';
?>

Now in your processing page (node/1 in this case), use the session data and better unset it after using, it totally depends on your logic though.

ressa’s picture

This is an old question and you can still use webform to collect and process data, but there is no 'Redirect POST Values' in the Drupal 7 version. In stead you can use GET to send your data to another path for further processing.

After creating your webform, with a URL path like "calculations/", go to Form settings -> Redirection location -> Custom URL: calculations/result?posted=%value[posted]&length=%value[length]&length=%value[length]

In stead of POST, use GET:

  $length = $_GET['length'];
  $width = $_GET['width'];
  $area = $length x $width x 337           //depends upon your formula
  switch($area) {
           case '...'
  }