PDA

View Full Version : Checking Form box and results next page


Al Capone
03-28-2006, 07:18 AM
Hello and good evening :),

Ok, first off a little background, I am trying to make a form with many checkboxes and if the checkboxes are selected the next page will display the names checked in link format in a code box so they can put the output of links on there own blog/myspace

Example (Form Page):


Check Boxes - Names
X - John
X - Mike
- George
X - Al


as you can see, George is not checked

Example of what I want on next page:



<a href="http://www.hsauifhusaihfiu.com/John.htm">John</a>
<a href="http://www.hsauifhusaihfiu.com/Mike.htm">Mike</a>
<a href="http://www.hsauifhusaihfiu.com/Al.htm">Al</a>



I want to do this because the people who visit my site don't know much html so they won't know how to do linking so I want to make it easier for them by making a form which they check and the output comes out in ready to paste html on the next page.

I would be greatful if someone could be kind enough to tell me how this may be accomplished.

V@no
03-28-2006, 01:30 PM
simply add in each checkbox: onClick="this.form.submit();"
if that doesnt work then maybe: onClick="forms['form name'].submit();"

degsy
03-28-2006, 01:56 PM
Are you outputting the names from a database?
Do you have user_id and user_name fields?


You can use the IN clause in your query


<input type="checkbox" name="user_id[]" value="<?php echo rs("user_id"); ?>">


That will create a $_POST value of
e.g.
$_POST['user_id'] = 1,2,4


sql = "SELECT * FROM table WHERE user_id IN (" . $_POST['user_id'] . ")"

Al Capone
03-28-2006, 03:12 PM
Thanks I'll try to use what you gave me, but is there simple script that does this too incase I have some trouble?, because I'm not to good with forms

Al Capone
03-28-2006, 10:30 PM
nevermind, im not going that path, im not going to use databases

degsy
03-29-2006, 04:34 PM
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>
<input name="name[]" type="checkbox" id="John" value="John" />
John
<br />
<input name="name[]" type="checkbox" id="Paul" value="Paul" />
Paul
<br />
<input name="name[]" type="checkbox" id="George" value="George" />
George
<br />
<input name="name[]" type="checkbox" id="Ringo" value="Ringo" />
Ringo</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>

<?php
if(isset($_POST['Submit'])){
$names = $_POST['name'];

if(is_array($names)){
foreach($names as $key => $name){
?>
&lt;a href=&quot;http://domain.com/<?php echo $name; ?>&quot;&gt;<?php echo $name; ?>&lt;/a&gt;<br />
<textarea name="textfield" cols="50"><a href="http://domain.com/<?php echo $name; ?>"><?php echo $name; ?></a></textarea>
<br />
<br />
<?php
}
}
}
?>