Hi, How can I pass the checkbox value="1" value="2"... to php script? If I have the html like this working ok input type="checkbox" name="month[]" value="january" />January But I want like this input type="checkbox" name="month[]" value="1" />January input type="checkbox" name="month[]" value="2" />February input type="checkbox" name="month[]" value="3" />March Php script $action .= (!empty($_POST['month'])? implode("",$_POST['month'])."\n" : ''); I think I need an array but how? I already try this but didt work $month=array( "1" => $month{January}, "2" => $month{February}, "3" => $month{March }, ); ?> Can you help me please? Thank you
input type="checkbox" name="month[1]" value="January" /> input type="checkbox" name="month[2]" value="February" /> .... Code (markup): foreach ($_POST['month'] AS $key => $month) { echo "{$key}: {$month}\n"; } PHP: ??
You were on the right track. Use a form like this: <form ... <input type="checkbox" name="month[]" value="January" /> January <input type="checkbox" name="month[]" value="February" /> February <input type="checkbox" name="month[]" value="March" /> March ... </form> Code (markup): Then in your PHP script, you can show each value: foreach ($_POST['month'] as $v) { echo $v . "\n"; } PHP: ... nico beat me
Thank you for you help but I dont want to have value="january"... input type="checkbox" name="month[]" value="1" />January input type="checkbox" name="month[]" value="2" />February input type="checkbox" name="month[]" value="3" />March I like to transport the value="1" to php script And in php have something like that $month=array( "1" => $month{January}, "2" => $month{February}, "3" => $month{March }, ); ?>
See my code again. name="month[1]" value="January" /> Code (markup): See the 1? That'll be the array key.
Sorry I did not explain well I dont want to see the months. January, February.... In html file. In html I want to see only numbers not the months. The months I like to put in php script. I dont know if is necessary arrays or not. I like to transport the value numbers and in php convert like this value="1" = January value="2" = February and so one Thank you bery much for you help
Okay, if I understood you right, this should work: function getmonth($id) { return date('F', mktime(0, 0, 0, intval($id))); } $_POST['month'] = array(); $_POST['month'][] = 1; $_POST['month'][] = 4; $_POST['month'][] = 6; $_POST['month'][] = 8; $_POST['month'] = array_map('getmonth', $_POST['month']); echo '<pre>' . print_r($_POST['month'], true) . '</pre>'; PHP:
$months = array(1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "Jun", 7 => "Jul", 8 => "Aug", 9 => "Sep", 10 => "Oct", 11 => "Nov", 12 => "Dec" ); if(isset($_POST['month'])) { foreach($_POST['month'] as $key => $value) { $month[ $value ] = $months[ $value ]; } } PHP: Is this what you're looking for?