Jump to content

Generate code with checkboxes ?


YFinn

Recommended Posts

 

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

 

 

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

 

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

 

Link to comment
Share on other sites

  • 4 weeks later...

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.

Link to comment
Share on other sites

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!

 

;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.