adm88
New Member
Posts: 10
|
Post by adm88 on Oct 10, 2012 22:25:02 GMT -5
So I almost finished coding my quiz and just realized that you asked to write the quizHandler as a new program. Can we write it as a function in a separate file and include it to the one with the form and use there?
If not - how are we supposed to send the data to the handler and make the form sticky at the same time?
What I'm having a hard time with is that I have my form in quiz.php and to make it sticky it sends itself back to quiz.php which runs the validation. If the user did't answer all the questions, or didn't put the name (s)he will see the form again, but what if the data was valid? How am I supposed to send it to the quizHandler?
To make it easier to understand, how to handle grade_quiz()?:
//check if the form was sent if( isset($_POST['sent']) && $_POST['sent'] == 'yes' ) { //if yes validates the data if(validate_data()) { //if data was valid grade the quiz grade_quiz(); //HOW TO SEND THIS ACTION TO A NEW FILE? }//end if else { //if not show the quiz again display_quiz($_POST); }//end else }//end if //if the form wasn't sent show the form else { display_quiz($_POST); }
Thanks
|
|
|
Post by Bob P on Oct 10, 2012 22:49:40 GMT -5
You do not need to send to a new file. Initially, I was thinking people might write a script that presents a form and in the action part of the form they would call another file to handle the results.
So, it's perfectly fine to use an include and a function to do what you need to do. There are many ways to code this HW assignment - don't feel limited by the directions.
Bob
|
|
|
Post by Bob P on Oct 10, 2012 23:09:40 GMT -5
I wanted to talk about about moving control to another file. The most common approach is through the use of a form and the action attribute. When you hit the submit button you run the script referenced by the action attribute and you send data via the GET or POST array.
Another way is to echo a link to the user and when they click it they go to another file and data is sent to the other file by appending it to the URl and you access it via the GET array.
Another is to use the Header command (see php manual). It is a redirect and often times more trouble than it is worth. It has a nasty habit of not working if you send anything to the browser first including white space.
And, of course using includes simulate the action of another file without losing control. This is used quite often and people will put their functions in diff files and include them when needed.
Anyway, I thought these ideas might be helpful. feel free to suggest others.
Bob
|
|