Jump to content

Direct to two different php pages based on form entry


ringartdesign

Recommended Posts

This may not be a php question or simply a html form question, but thought I'd try. I have a html form: https://2stephealth.com/get_quote.html  That directs to a php page that calculates a quote based on their age, gender, etc. This works perfectly as is, however, if a person is 65 or older the form returns $0 on quote.php. How can I have the form return a brand new quote page (quote_seniors.php) if the person enters an age of 65 or older?

 

Here is my php processing:

<?php

if (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="male"))

$quote=31.44;

elseif (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="female"))

$quote=44.65;

elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] =="male"))

$quote=35.91;

elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] =="female"))

$quote=50.33;

elseif (($_POST['age'] >= 31) && ($_POST['age'] <= 35) && ($_POST['sex'] =="male"))

$quote=40.78;

elseif (($_POST['age'] >= 31) && ($_POST['age'] <= 35) && ($_POST['sex'] =="female"))

$quote=62.11;

elseif (($_POST['age'] >= 36) && ($_POST['age'] <= 40) && ($_POST['sex'] =="male"))

$quote=51.33;

elseif (($_POST['age'] >= 36) && ($_POST['age'] <= 40) && ($_POST['sex'] =="female"))

$quote=76.72;

elseif (($_POST['age'] >= 41) && ($_POST['age'] <= 45) && ($_POST['sex'] =="male"))

$quote=65.95;

elseif (($_POST['age'] >= 41) && ($_POST['age'] <= 45) && ($_POST['sex'] =="female"))

$quote=92.55;

elseif (($_POST['age'] >= 46) && ($_POST['age'] <= 50) && ($_POST['sex'] =="male"))

$quote=87.87;

elseif (($_POST['age'] >= 46) && ($_POST['age'] <= 50) && ($_POST['sex'] =="female"))

$quote=108.38;

elseif (($_POST['age'] >= 51) && ($_POST['age'] <= 60) && ($_POST['sex'] =="male"))

$quote=117.51;

elseif (($_POST['age'] >= 51) && ($_POST['age'] <= 60) && ($_POST['sex'] =="female"))

$quote=126.65;

elseif (($_POST['age'] >= 61) && ($_POST['age'] <= 64) && ($_POST['sex'] =="male"))

$quote=184.07;

elseif (($_POST['age'] >= 61) && ($_POST['age'] <= 64) && ($_POST['sex'] =="female"))

$quote=168.87;

 

//add spouse

if (($_POST['spouse_age'] >= 18) && ($_POST['spouse_age'] <= 25) && ($_POST['spouse_sex'] =="male"))

$quote+=31.44;

elseif (($_POST['spouse_age'] >= 18) && ($_POST['spouse_age'] <= 25) && ($_POST['spouse_sex'] =="female"))

$quote+=44.65;

elseif (($_POST['spouse_age'] >= 26) && ($_POST['spouse_age'] <= 30) && ($_POST['spouse_sex'] =="male"))

$quote+=35.91;

elseif (($_POST['spouse_age'] >= 26) && ($_POST['spouse_age'] <= 30) && ($_POST['spouse_sex'] =="female"))

$quote+=50.33;

elseif (($_POST['spouse_age'] >= 31) && ($_POST['spouse_age'] <= 35) && ($_POST['spouse_sex'] =="male"))

$quote+=40.78;

elseif (($_POST['spouse_age'] >= 31) && ($_POST['spouse_age'] <= 35) && ($_POST['spouse_sex'] =="female"))

$quote+=62.11;

elseif (($_POST['spouse_age'] >= 36) && ($_POST['spouse_age'] <= 40) && ($_POST['spouse_sex'] =="male"))

$quote+=51.33;

elseif (($_POST['spouse_age'] >= 36) && ($_POST['spouse_age'] <= 40) && ($_POST['spouse_sex'] =="female"))

$quote+=76.72;

elseif (($_POST['spouse_age'] >= 41) && ($_POST['spouse_age'] <= 45) && ($_POST['spouse_sex'] =="male"))

$quote+=65.95;

elseif (($_POST['spouse_age'] >= 41) && ($_POST['spouse_age'] <= 45) && ($_POST['spouse_sex'] =="female"))

$quote+=92.55;

elseif (($_POST['spouse_age'] >= 46) && ($_POST['spouse_age'] <= 50) && ($_POST['spouse_sex'] =="male"))

$quote+=87.87;

elseif (($_POST['spouse_age'] >= 46) && ($_POST['spouse_age'] <= 50) && ($_POST['spouse_sex'] =="female"))

$quote+=108.38;

elseif (($_POST['spouse_age'] >= 51) && ($_POST['spouse_age'] <= 60) && ($_POST['spouse_sex'] =="male"))

$quote+=117.51;

elseif (($_POST['spouse_age'] >= 51) && ($_POST['spouse_age'] <= 60) && ($_POST['spouse_sex'] =="female"))

$quote+=126.65;

elseif (($_POST['spouse_age'] >= 61) && ($_POST['spouse_age'] <= 64) && ($_POST['spouse_sex'] =="male"))

$quote+=184.07;

elseif (($_POST['spouse_age'] >= 61) && ($_POST['spouse_age'] <= 64) && ($_POST['spouse_sex'] =="female"))

$quote+=168.87;

?>

I would probably use JS for this.

 

create a function that is called when the form is submitted

 

get the value of the age text field and then use an IF statement to set the action of the form

 

NB: you will need to ad and id attribute to your inputs

 

something like:

 

function checkAge() {

  var age = document.getElementById('age').value;

 

  if(parseInt(age) >= 65) {

    document.quote.Action = "https://www.2stephealth.com/quote_seniors.php";

  }

}

 

that should then submit to the other page if the age is 65+

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.