I am working on a survey and I am having a conceptual problem, I am not new to programming but I am new to web programming. I am trying to set up a dynamic form. I want to ask the user if they want a conference yes/no and if they said yes I want them to answer more questions about their wishes for the conference. If no I want them to go on to answer more questions about a different topic on the next page. Everything will be going into a MySQL database. How do I get it to 'trigger' a screen refresh after they say yes / no. Conceptually I am not sure how much of this should be done in PHP and HTML, right now I am trying to do it all in PHP. Any thoughts or guidance is greatly appreciated.

Can

** Excerpt of code ****
<body>
<?PHP
print("<form name=\"ConferenceSection\" method=\"post\" action=\"> ");
print("<div align=\"center\">");
print(" <center>");
print(" <table class=\"mainFrame\" cellspacing=\"0\">");
print(" <tr>");
print(" <td class=\"mainFrame2ColSpan2\" colspan=\"2\">");
print(" <p class=\"pageNumber\">Page 3 of 6</p></td>");
print(" </tr>");
print(" <tr>");
print(" <td class=\"mainFrame2ColSpan2\" colspan=\"2\" >");
print(" <p class=\"heading\">Section 1: Conference Questions</p></td>");
print(" </tr>");
print(" <tr>");
print(" <td class=\"mainFrame2ColSpan2\" colspan=\"2\">");
print(" <p class=\"spacerWhite\"></p></td>");
print(" </tr>");
print(" <tr>");
print(" <td class=\"mainFrame2ColSpan2\" colspan=\"2\">");
print(" <p class=\"questions\">CEPA is considering holding an emergency preparedness conference in 2006.&nbsp; We need your help to plan for this event.&nbsp; Please answer the following questions to help us with our planning process.</p></td>");
print(" </tr>");
print(" <tr>");
print(" <td class=\"mainFrame2ColSpan2\" colspan=\"2\">");
print(" <p class=\"spacerWhite\">
</p></</td>");
print(" </tr>");
print(" <tr>");
print(" <td class=\"mainFrame2ColNumberSpan1\" valign=\"top\"><p class=\"questions\">1.
</p></td>");
print(" <td class=\"mainFrame2ColQuestionSpan1\"><p class=\"questions\">Would you attend an emergency management conference in Halifax, Nova Scotia?</p></td>");
print(" </tr>");
print(" <tr>");
print(" <td class=\"mainFrame2ColNumberSpan1\"></td>");
print(" <td class=\"mainFrame2ColQuestionSpan1\">");
print(" <div align=\"left\">");
print(" <table class=\"nestFrame\" cellspacing=\"0\">");
print(" <tr>");
print(" <td class=\"nestFrame2ColButtonSpan1\"><p class=\"questions\"><input type=\"Radio\" name=\"Question1\" value=\"Yes\"><echo $Question1></p></td>");
print(" <td class=\"nestFrame2ColOptionSpan1\"><p class=\"questions\">Yes</font></td>");
print(" </tr>");
print(" <tr>");
print(" <td class=\"nestFrame2ColButtonSpan1\"><p class=\"questions\"><input type=\"Radio\" name=\"Question1\" value=\"No\"><echo $Question1></p></td>");
print(" <td class=\"nestFrame2ColOptionSpan1\"><p class=\"questions\">No</p></td>");
print(" </tr>");
print(" </table>");
print(" </div>");
print(" </td>");
print(" </tr>");
print(" <tr>");
print(" <td class=\"mainFrame2ColSpan2\" colspan=\"2\">");
print(" <p class=\"spacerWhite\">_</p></td>");
print(" </tr>");

switch($Question1) {
case 'Yes':
print(" <tr>");
print(" <td class=\"mainFrame2ColNumberSpan1\" valign=\"top\"><p class=\"questions\">2.*</p></td>");
print(" <td class=\"mainFrame2ColQuestionSpan1\"><p class=\"questions\">How many days would you be prepared to attend an emergency preparedness conference?</p></td>");
print(" </tr>");
.....
break;
}
print(" </table>");
print(" </center>");
print("</div>");
print("</form>");
?>
</body>

</html>

    Use javascript at the client end to trigger a submit when the option is selected.

      I don't know squat about JavaScript and learning the PHP / MySQL stuff right now is enough of a challenge and making my head spin. My boss wanted this done last week, so I was hoping to not go down the path of learning Javascript. Is it possible to do it in PHP?

        Well only if you use submit normally. PHP is serverside so unless the user actually submits a form or requests a page you can't interact the way you want.

          Thanks. I would I do it if I use submit normally? I am trying to determine if the webpage they see should be a .php or a .html. I need to do three dynamic things with the page. Any guidance is greatly appreciated.

            They will only see html whether or not is it generated with php or not. PHP is server side so it has no place on the client.

              PHP = Server side got it. I guess my confusion is because when I see different webiste, including the one we are posting on they have a php extension.

                Yes - the request is to a php page but that page ends up serving only html. Some sites are built with all pages in php but the files are named htm and the server is set up to pass all page requests through php.

                  That concept makes sense. I want to learn more about idea "Some sites are built with all pages in php but the files are named htm and the server is set up to pass all page requests through php." but I am having a hard time finding info on the web. I spent the day on google and any site I found did not expand on this. Do you know of a good website I could look at?

                    As subway already said in answer to your original question, what you are trying to do will not be possible unless you use javascript. To do this, you could simply use:

                    No: <input type="radio" name="conference" value="no" onclick="document.ConferenceSection.submit()" />

                    And when they select no it will submit the form.

                      Can75 wrote:

                      That concept makes sense. I want to learn more about idea "Some sites are built with all pages in php but the files are named htm and the server is set up to pass all page requests through php." but I am having a hard time finding info on the web. I spent the day on google and any site I found did not expand on this. Do you know of a good website I could look at?

                      How you do it depends on what server you're using. All of them would require being told that ".php" means a PHP script, and you can tell them that ".html" means a PHP script as well - the server doesn't care what the page is called as long as it can work out what it's supposed to be serving. File names are not URLs.

                      For an example, PHP's installation instructionss for Apache2.0 has the step:

                      Tell Apache to parse certain extensions as PHP. For example, let's have Apache parse the .php extension as PHP. You could have any extension(s) parse as PHP by simply adding more, with each separated by a space. We'll add .phtml to demonstrate.

                      AddType application/x-httpd-php .php .phtml

                      Nothing is stopping you from adding [font=monospace].html[/font] to that list.

                      For more on the subject about URIs and stuff like that, have a look around the Web's home site http://www.w3.org/ - e.g., http://www.w3.org/Provider/Style/URI (part of http://www.w3.org/Provider/Style/ ) http://www.w3.org/TR/chips/#uri , http://www.w3.org/QA/Tips/uri-choose and so on.

                        That JavaScript does not seem that difficult, the reason why I was so keen to stay away from it was because of something else I need to do in the form. I will have a list of 10 things (option buttons) then the user will rank their preferences between 1 and 10, as they rank their preferences, the option they just selected disappears from that list and appears below that will the corresponding rank. Make sense? How do I do that in Javascript?

                          A Javascript forum would be a better place to ask something like that: there'd be a higher proportion of Javascript experts there, for example.

                            I kinda got lost reading through the posts trying to figure out what you've resolved and what you still need to do, however here are a few pointers for PHP and forms...

                            1) a shortcut for echo is <?="VALUE"?> or <?=$var?> so to save the values of form elements you may use <input type=text name=input1 value="<?=$POST['input1']?>">
                            For boxes and radios you can do something like $SELECTED = (isset($
                            POST['boxName'])) ? "SELECTED" : null; and then your input would look like this <input type=checkbox name=boxName $SELECTED>

                            2) To submit the form automatically the javascript is very simple, just include an onBlur or onChange event in the tag. <input type=radio name=conf value=yes onBlur="form.submit()"> where form is the name of your form. onBlur is used when the object looses focus and onChange is used when the value of the object is changed.

                            3) You can also include every possible element you might need and modify the type attribute. <input type=hidden name=derivedElement > will hide the input so if you have a radio button you can include onChange="document.formName.derivedElement.type='text'" This will now display the hidden element as you wish.

                            4) Most elements include an 'innerHTML' property which you can play with... so you may include sections of the form in a <div> tag and use javascript to modify the innerHTML of the div for example: <div name=divblock></div> <input type=button onClick="document.divblock.innerHTML='<input type=text name=textName>'"> will create an input when the button is clicked...

                            5) CSS can also be used to hide and display elements. <input type=text name=textName style="visibility: hidden"> will create a input that should not be displayed by default. but onChange="formName.textName.style='visibility: block'" will now display the element.

                            I hope some of this helped, reply with what you want so I can more specifically help you

                              quick note on above post the #5

                              i think it should be Display CSS insted of Visiablity

                              <input type=text name=textName style="display: none;">
                              then
                              JS to display the text field......
                              onChange="formName.textName.style.display = 'block'; "

                                Write a Reply...