Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Forms that return answers depending on input

Featured Replies

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>

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.

  • Author

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

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/manual/en/function.header.php

http://php.net/manual/en/control-structures.if.php

http://php.net/manual/en/control-structures.switch.php

 

Cheers

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.