Forum Moderators: coopster

Message Too Old, No Replies

Complex Logic Problem

         

woldie

2:10 pm on Apr 25, 2004 (gmt 0)

10+ Year Member



Hi Guys,

I've got this complex logic problem. Basically I've got this form with drop down boxes, and depending on what you select it redirects.

The form is based on property, so you have to answer specific questions so that you can qualify.

Here are some sample questions:

1. Where is your property?

England (means continue)
Scotland (means continue)
Wales (means continue)
Northern Ireland (means contact whoever)
Isle of Man (means we cannot help)
Channel Islands (means we cannot help)
Other (means we cannot help)

2. Is your property of standard brick or stone construction?

Yes (means continue)
No (means contact joe bloggs)

3. Is your property above, beside, opposite or adjacent to any commercial premises?

Yes (means contact joe bloggs)
No (means continue)

How my script works is that if you select the questions which allows you to continue, it redirects to a page with the variables passed. This works

If you select 'Northern Ireland' this redirects to a page in which you have to contact somone. This works

if you select 'Isle of Man', 'Channel Islands' or 'other' it redirects to a page in which they cannot help. This works

However this is where my logic falls down, if you select 'England' in question 1 and then select 'No' then it should redirect to a page where you should contact someone however this does work because it thinks you can continue.

Sounds easy but not.

Below is my code, please note that there other questions but this is the first three, so below is the full PHP code.

Feel free to have a go, like I said I'm nearly with it.

Big Thanks :o)

PHP Code

<?
if ($property == 'Northern Ireland')
{
// setup redirection
$contact_ypf=1;
}

if (($property == 'Isle of Man') ¦¦ ($property == 'Channel Islands') ¦¦ ($property == 'Other'))
{
// setup redirection
$cannot_help=1;
}

if (($property == 'England') ¦¦ ($property == 'Scotland') ¦¦ ($property == 'Wales'))
{
$contact_ypf=0;
$continue=1;
}

// QUESTION 2
if ($property_type == 'null')
{
$found=1;
$invalid2=1;
}
if ($property_type == 'Yes')
{
$contine=1;
}
elseif ($property_type == 'No')
{
// setup redirection
$contact_tml=1;
}

<snipped large code dump from here - jatar_k>

if ($found==1) {
// this goes back to the page where the user has not filled any of the drop down boxes
header("Location: [example.com...]
} else {

// this is where my logic goes astray slightly

// if answer the question correctly, then goes to a continue page
if ( ($continue==1 && ($property=='England' ¦¦ $property=='Scotland' ¦¦ $property=='Wales')) ) {
header("Location: [example.com...]
}
// this is where it goes to contact another company - this works
elseif ($contact_ypf==1) {
header("Location: [example.com...]
}
// this is where they cannot help you - this works
elseif ($cannot_help==1) {
header("Location: [example.com...]
}
// this is where they contact the company, this where it should go if you answer quest 1 to continue and quest 2 to 'no'
elseif ($contact_tml==1) {
header("Location: [example.com...]
}
}
?>

[edited by: jatar_k at 3:08 pm (utc) on April 25, 2004]

hakre

2:28 pm on Apr 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi woldie,

your script is quite complex so i did not went through it completely. but maybe this idea will help you:

do not only pass the answer (continue, contact xy, no help), pass your question number, too.

that way you can easily decide what to do next.

for example:
if it's question 1 with answer continue, then pass on with question 2 etc.

you can use an

<input type="hidden" name="question" value="[i]#n[/i]" />
hidden input element in each form to 'tag' it with the question number.

i hope you can follow my idea and this will help you out of your logical problem.

--hakre

woldie

2:50 pm on Apr 25, 2004 (gmt 0)

10+ Year Member



Hi hakre,

Thanks for replying back, however my form is one page, with all questions, I have posted the form below, the script works well but just falls over when you answer those possibiliies.

Any further ideas?

Cheers. :o)

jatar_k

3:11 pm on Apr 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If there are combined cases like you are saying then you should be combining your value tests

if (($property == 'England') ¦¦ ($property == 'Scotland') ¦¦ ($property == 'Wales'))

maybe you can add a check for the other var in there or assuming this is the test for your other var

elseif ($property_type == 'No')

you may need to reset some other vars if it is set to NO

woldie

3:25 pm on Apr 25, 2004 (gmt 0)

10+ Year Member



Hi Jatar_k,

Thanks for the advice, I think I'll try that approach, looks like thats the best way.

Cheers