Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 24th, 2003, 09:17 AM
anish anish is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 12 anish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
str_replace with checkboxes

Hi All,

here is my code
test.html
[html]<td bgcolor="{COLOR}">{PICK}</td>[/html]

Please note, that code above is inside an HTML file.

test.php
PHP Code:
<?
session_start
();
$filename "test3.html";
$fd fopen ($filename"r");
$filefread ($fdfilesize ($filename));
$file str_replace("{PICK}"'test1 <input type="checkbox" name=mycheckbox[] value="5" checked>'$file);
print(
$file);
?>
<!--
test2 <INPUT type='checkbox' name='<? echo $mycheckbox?>' value='XYZ' checked><BR>
-->
<?
//$test = $_POST['mycheckbox'];
// $mycheckbox = mycheckbox;
if(isset($_POST['mycheckbox'])){
 if (isset(
$mycheckbox)){

// $mycheckbox = explode(",",$mycheckbox);
foreach ($mycheckbox As $key => $age_range) {
print 
$age_range .'='$key;
}
}
}

//foreach ($mycheckbox as $checkbox){
//$authstatus = (isset($checkbox) ? 1 : 0);
//print $authstatus;
//}
//foreach($select as $name => $val)

//foreach ($_POST as $mycheckbox => $value)
foreach ($test as $te => $value)
{
    print 
'PASS NUMBER 1';
}
    print 
'REACHED THE END';

?>


All I want to do is somehow get the Checkbox value (5) printed somewhere, but only if the checkbox is checked.
I know I have a lot of duff code, so please feel free to remove any unwanted code. (Its all my testing and trying - to no avail)

Now you will notice that the Checkbox is inside a STR_REPLACE. It has to be like this unfortunetly and I'm getting to a stage where I think its imposible to find the value of the checkbox when its checked.

Please help.

Thanks,
ANISH

Reply With Quote
  #2  
Old March 24th, 2003, 11:56 AM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,344 jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 6 h 26 m 32 sec
Reputation Power: 787
Change the value of your checkbox to one for easier testing, and put the range (or what you have as your current value) inside the array name of the form field. Well that reads a little confusing, how about I show you.
PHP Code:
 session_start();
$filename "test3.html";
$fd fopen ($filename"r");
$filefread ($fdfilesize ($filename));
$file str_replace("{PICK}"'test1 <input type="checkbox" name="mycheckbox[5]" value="1" checked>'$file); // quotes around mycheckbox[], note value changes
print($file);

if(isset(
$_POST['mycheckbox']))
  {
  foreach(
$_POST['mycheckbox'] as $value => $checked)
    {
    if(
$checked// easy testing, $checked is 1 (TRUE) if checked
      
{
      echo 
$value ' was checked<br>';
      }
    }
  } 

Reply With Quote
  #3  
Old March 24th, 2003, 09:05 PM
anish anish is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 12 anish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks jharnois

Much appreciated.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > str_replace with checkboxes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway