close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Page redirect after submit

Thread began 10/07/2011 1:57 am by jvorzimer358609 | Last modified 10/10/2011 3:55 pm by Jason Byrnes | 854 views | 7 replies |

jvorzimer358609

Page redirect after submit

I am putting together a form to get answers to some questions and need to check the score and redirect to one of 2 pages depending upon the score they get.

I'm just starting to wade my way through Data Assist so I'm a little slow with this so far.

Sign in to reply to this post

Jason ByrnesWebAssist

  and need to check the score  


so this is a test of some sort?

This is going to take some custom coding to accomplish

you will need to have a database with a table of answers:
answers:
answerID - Primary Key
answerText - varchar

then create a recordset to look up the answers entered and compare them against the answers in the db, using the COUNT function you can return a number of matches.


for example, lets say you have form elements named "answerOne" and "answerTwo". create the recordset using advaced view as:

SELECT COUNT(answerID) as testScore
FROM answers
WHERE answerText = paramAnswerOne AND answerText = paramAnswerTwo

in the Variables section, create the two parameters:

Name: paramAnswerOne
Type: text
Default value: -1
Runtime Value: $_POST['answerOne']

Name: paramAnswerTwo
Type: text
Default value: -1
Runtime Value: $_POST['answerTwo']



the you can use an if statement to do the redirect based on the testScore from the recordset

php:
<?php 

if($row_recordsetName['testScore'] == 2) {
    
header("Location: page1.php");
} else {
    
header("Location: page2.php");
}
?>
Sign in to reply to this post

jvorzimer358609

Thanks Jason

Actually there are only four questions and they need to answer yes to each one to "pass". It is a "test" of how they personally evaluate their progress in the materials on the site. Once they can answer yes to all the questions their status is upgraded and they get more materials. The redirect is needed so send them to one of two pages to inform them whether they are moving ahead or need to continue at their current level.

Honestly, I have struggled a bit with header calls. If I understand correctly, this code must go above the DOCTYPE declaration so it exists before any HTML is present.

Sign in to reply to this post

Jason ByrnesWebAssist

ok, that's a little simpler:


php:
<?php 
if($_SERVER['REQUEST_METHOD'] == "POST") {
   if((isset(
$_POST['element1']) && $_POST['element1'] == "yes") && (isset($_POST['element2']) && $_POST['element2'] == "yes") && (isset($_POST['element3']) && $_POST['element3'] == "yes") && (isset($_POST['element4']) && $_POST['element4'] == "yes")) {
       
header("Location: page1.php");
     } else {
       
header("Location: page2.php");
   }
}
?>





yes, the header code needs to come before any HTML on the page.

Sign in to reply to this post

jvorzimer358609

OK - I know I am being a bit simple here but I'm still having trouble with this redirect. Once I have this working I can do the DB update for their status. Here is the error msg I am getting:

Warning: Cannot modify header information - headers already sent by (output started at /homepages/46/d366494719/htdocs/myoscript3/php/modules.php:4) in /homepages/46/d366494719/htdocs/myoscript3/php/modules.php on line 30

I have attached a zip of the page with the form.

Attached Files
modules.zip
Sign in to reply to this post

Jason ByrnesWebAssist

the error is caused by the blank line at line 3.


see this thread for details on the headers already sent error and how to troubleshoot it:
showthread.php?t=19285

Sign in to reply to this post

jvorzimer358609

I got rid of the error msg but no matter what input I send with the form the same (modules.php) page comes back up so the redirect isn't taking place for some reason.

I'm still struggling with the whole header call - it's always seemed to be something I have trouble grasping.

Thanks for all the help Jason.

Attached Files
modules.zip
Sign in to reply to this post

Jason ByrnesWebAssist

my initial code had a misspelling of "Location.


change:
header("Locaion: modulesPos.php");
} else {
header("Locaion: modulesNeg.php");


to:
header("Location: modulesPos.php");
} else {
header("Location: modulesNeg.php");

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...