kks_krishna Posted July 10, 2007 Share Posted July 10, 2007 HI, I have added 10 check boxhes in my html form. When I am submit the form it will be taken to info.php page.Now i want to get all the check boxes selected. How can I do that in PHP? Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/ Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 HI, I have added 10 check boxhes in my html form. When I am submit the form it will be taken to info.php page.Now i want to get all the check boxes selected. How can I do that in PHP? first try to be clear is typographical or grammatical joke any ways use the post method $_POST['name of text box here']; and by the way are u using array on that chk box Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294068 Share on other sites More sharing options...
kks_krishna Posted July 10, 2007 Author Share Posted July 10, 2007 Can i use like this : $labels = $_GET['labels']; Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294070 Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 if u are using post then $labels = $_POST['labels']; but if you get data from url $labels = $_GET['labels']; Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294071 Share on other sites More sharing options...
kks_krishna Posted July 10, 2007 Author Share Posted July 10, 2007 Thanks. For reteriving I am using like this : <?php print("Label :".$labels[1]); ?> But its showing only the single character. Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294072 Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 foreach($_POST['label'] as $value) { echo $value; } //that is good if you name label as array like name="label[]" Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294073 Share on other sites More sharing options...
kks_krishna Posted July 10, 2007 Author Share Posted July 10, 2007 I used like this : <?php foreach($labels as $value) { echo $value; } ?> getting error like this : Warning: Invalid argument supplied for foreach() in /home/content/k/k/s/kkskrishna/html/dlinks/add_link.php on line 47 Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294077 Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 $labels is this an array Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294080 Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 Can we see your form? Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294081 Share on other sites More sharing options...
kks_krishna Posted July 10, 2007 Author Share Posted July 10, 2007 <form name="add_links" action="add_link.html"> <?php include("templates/link_header.php"); ?> <div id="contents"> <table> <tr> <td class="text_format"> Link Text <?php foreach($labels as $value) { echo $value; } ?> </td> <td > <input type="text" size="30" name="link_text"> </td> </tr> <tr> <td class="text_format"> Link URL </td> <td> <input type="text" size="30" name="link_url"> </td> </tr> <tr> <td class="text_format"> Description </td> <td> <textarea rows="10" cols="40" name="link_desc"></textarea> </td> </tr> <tr> <td class="text_format"> Label </td> <td> <input type="checkbox" name="labels" value="spring">Spring <input type="checkbox" name="labels" value="hibernate">Hibernate <input type="checkbox" name="labels" value="seam">JBoss Seam <input type="checkbox" name="labels" value="javafx">JavaFX <input type="checkbox" name="labels" value="jsf">JSF <input type="checkbox" name="labels" value="struts">Struts<br> <input type="checkbox" name="labels" value="jsp">JSP <input type="checkbox" name="labels" value="servlets">Servlets <input type="checkbox" name="labels" value="ejb">EJB <input type="checkbox" name="labels" value="jta">JTA <input type="checkbox" name="labels" value="jms">JMS <input type="checkbox" name="labels" value="jni">JNI<br> <input type="checkbox" name="labels" value="stripes">Stripes <input type="checkbox" name="labels" value="tapestry">Tapestry <input type="checkbox" name="labels" value="wicket">Wicket <input type="checkbox" name="labels" value="eclipse">Eclipse <input type="checkbox" name="labels" value="netbeans">NetBeans <input type="checkbox" name="labels" value="faqs">Interview Questions<br> <input type="checkbox" name="labels" value="java5">Java 5.0 <input type="checkbox" name="labels" value="java6">Java 6.0 <input type="checkbox" name="labels" value="java7">Java 7.0 <input type="checkbox" name="labels" value="scjp">SCJP <input type="checkbox" name="labels" value="scwcd">SCWCD <input type="checkbox" name="labels" value="scbcd">SCBCD<br> <input type="checkbox" name="labels" value="scja">SCJA <input type="checkbox" name="labels" value="scdjws">SCDJWS <input type="checkbox" name="labels" value="scea">SCEA </td> </tr> <tr> <td> <input type="submit" onclick="return validateLink()" value="Submit"> </td> </tr> </table> <?php $link_text = $_GET['link_text']; $link_url_id = ""; $link_url = $_GET['link_url']; $link_desc = $_GET['link_desc']; $link_tag = $_GET['link_tag']; $labels = array(); $this->$labels = $_GET['labels']; foreach($labels as $value) { echo $value; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294083 Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 All these... <input type="checkbox" name="labels" value="spring">Spring Need to be.... <input type="checkbox" name="labels[]" value="spring">Spring Then... <?php foreach($_GET['labels'] as $value) { echo $value; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294084 Share on other sites More sharing options...
kks_krishna Posted July 10, 2007 Author Share Posted July 10, 2007 HI, Now i got the problem. Its working. The problem is i am using URL rewriting. so its not able to get the values. Do you have any idea how to get the values when doing URL rewriting. basically file name is add_link.php. after url re wrting it is add_link.html Please help me. Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294087 Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 This problem is unrelated. Id'e suggest posting your .htaccess and a description of your problem in the mod_rewrite board. Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294090 Share on other sites More sharing options...
kks_krishna Posted July 10, 2007 Author Share Posted July 10, 2007 Thanks, don't mind, do you have any forums in PHP freaks related to .htaccess problems. Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294093 Share on other sites More sharing options...
kks_krishna Posted July 10, 2007 Author Share Posted July 10, 2007 HI, What is the problem if i am using the checkbox name without "[]". PHP is taking values only when we are using the "[]". but javascript is not working. so I have removed []. Please help me how to fix this problem. <input type="checkbox" name="labels" value="spring">Spring <input type="checkbox" name="labels" value="hibernate">Hibernate <input type="checkbox" name="labels" value="seam">JBoss Seam <input type="checkbox" name="labels" value="javafx">JavaFX <input type="checkbox" name="labels" value="jsf">JSF <input type="checkbox" name="labels" value="struts">Struts<br> <input type="checkbox" name="labels" value="jsp">JSP foreach($_GET['labels'] as $value) { echo $value; } Quote Link to comment https://forums.phpfreaks.com/topic/59197-how-to-reterive-check-box-info/#findComment-294274 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.