YFinn Posted March 17, 2007 Share Posted March 17, 2007 I would like to know the following: At the moment I know that it is possible with <? include ("info1.htm");?> to get information into lets say a html table. This way you can put together a result page with information coming from different html files. What I actually want is a html page with several checkboxes each checkbox should represent a html page / code with information. If visitors mark lets say 3 checkboxes of 5 then the information represented behind the marked checkboxes should be send to a result page. The result is a page put together with info coming from the marked checkboxes. But how do I tell a checkbox that it has to fetch information with <? include ("info1.htm");?> And another checkbox lets say <? include ("info2.htm");?> and again another checkbox <? include ("info3.htm");?> and put these together into one result page? Greetings YFinn Quote Link to comment Share on other sites More sharing options...
Glyde Posted March 17, 2007 Share Posted March 17, 2007 <?php if ( isset( $_POST['submit'] ) ) { if ( $_POST['checkBox1'] ) include "htmlpage1.html"; if ( $_POST['checkBox2'] ) include "htmlpage2.html"; } ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <input type="checkbox" name="checkBox1" value="1" /> <input type="checkbox" name="checkBox2" value="1" /> <input type="submit" name="submit" value="Submit" /> </form> There are much better and cleaner ways to do it...but this just gives you a rough example. Quote Link to comment Share on other sites More sharing options...
YFinn Posted March 18, 2007 Author Share Posted March 18, 2007 Thank you very much Glyde for the quick response, tried the script and its working. Of course it is not yet the way that I want it, but for someone who is new to PHP it is cool to see a script working. And I got the feeling that I am on my way towards a solution. By the way you mentioned that there are better ways to do this, are they very difficult. Greetings YFinn Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 14, 2007 Share Posted April 14, 2007 No, they aren't complicated; however, PHP is a language you learn one step at a time. Don't go overboard, or you'll find yourself back here on a daily basis looking for answers. Start of small, write test scripts. Then create a local server on your computer, and start trying scripts. Make some scripts that use sockets, some that connect to SQL servers, some that manage files, and some that integrate all 3. If you do things like this, you can be an excellent PHP coder in a small amount of time. Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted April 14, 2007 Share Posted April 14, 2007 Here's another method: <?php if ( isset( $_POST['submit'] ) ) { if(count($_POST['checkBox']) > 0){ foreach($_POST['checkBox'] as $checkbox_file) include $checkbox_file; } } // Create an array of files that can be included $include_files = array("file1.html", "file2.html", "file3.html"); ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <?php foreach($include_files as $file) echo $file.': <input type="checkbox" name="checkBox[]" value="'.$file.'" /><br>'; ?> <input type="submit" name="submit" value="Submit" /> </form> Just add all the names of the files that can be included into the $include_files variable and you'll be all set. Also, Glyde is correct. PHP is best learned by messing around with it. Try things, be willing to make mistakes, and ask for help when you get stuck. Good luck! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.