Web Design Forum: Forms that return answers depending on input - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Forms that return answers depending on input Rate Topic: -----

#1 User is offline   cre8tive-lane 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 24-January 12
  • Reputation: 0

Posted 24 January 2012 - 07:36 PM

I was wondering if someone could give me some help...

My form is below - basically it has 2 drop down menus and a search button. The first drop down is 'Interests' and offers a range of options. The second is 'Experience' and offers a range of years experience.

So what the user will do is choose a interest and then choose the amount of years experience they have - depending on the choices they will be forwarded to a relevant page.

I normally work this stuff out myself through Google but i don't even know what you call this type of web form work! Any pointers would be a massive help.

<form id="devroutes" name="devroutes" method="post" action="php??">
<p class="pinkpara"> Interests :
<select name="xlevl" id="xlevl">
<option>(please select)</option>
<option>HR</option>
<option>Management</option>

<option>In-house training</option>
<option>Not sure</option>
<option>Something else etc</option>
</select>
</p>
<p class="pinkpara">Exeprience : <select name="xlevl" id="xlevl">
<option>(in years)</option>

<option>1 - 2</option>
<option>3 - 5</option>
<option>5 - 7</option>
<option>8 +</option>
</select>
</p>
<p><input name="srch" type="button" value="Search" /></p>

</form>
0

#2 User is offline   simplypixie 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 62
  • Joined: 23-November 11
  • Reputation: 11
  • Gender:Female
  • Location:Shropshire
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 25 January 2012 - 07:17 AM

In your form action redirect the submitted form data to the page where you are going to run the PHP that selects and displays information from the database based on the submitted options, for example
<form id="devroutes" name="devroutes" method="post" action="resultspage.php">

Then for all of your menu options you need to set a value and it is this value that will be used to select the correct data from the database so it will depend on how you sotre it, but if sotred by the same values as those displayed in the option text, it would be something like this:
<option value="HR">HR</option>
.
.
<option value="2">1 - 2</option>

This is just an example of how you need to do it and you will have to format as needed.
0

#3 User is offline   cre8tive-lane 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 24-January 12
  • Reputation: 0

Posted 31 January 2012 - 07:35 PM

Thanks simplypixie.

I've made the changes and understand the process needed, any ideas how i would go about coding the php?

Obviously first connect to db - then would you use a chain of if statments or would that bog the code down a bit? Do you know anywhere in the forums with any initial scripting to use?

Thanks
James
0

#4 User is offline   AdvantageDigitalMedia 

  • Forum Newcomer
  • Group: Gold Membership
  • Posts: 21
  • Joined: 31-January 12
  • Reputation: 1

Posted 31 January 2012 - 09:35 PM

Hi,

If you're going to be forwarding users to different areas, the combination of an if statement and a header redirect would work, like:

if($number >= "5"){ header('Location: http://www.yourdomain.com/page1'); }


Just an example obviously but a combination of these techniques will achieve what you wish. Remember, if using the header statement you must not render any HTML before this in your php "processor" file, resultspage.php.

Furthermore, if you're having a lot of redirects or potential "if" statements, consider using the switch function instead.

See these links for more info:
http://php.net/manua...tion.header.php
http://php.net/manua...ructures.if.php
http://php.net/manua...ures.switch.php

Cheers
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users