 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
dgs
Joined: 13 May 2008 Posts: 20
|
Posted: Tue Jul 08, 2008 11:20 pm Post subject: SOLVED: problems understanding grouped items, such as date |
|
|
I am having problems figuring out how to get at the data that is in a group. I am including code that I have captured from several sources, but I don't know how to read the value.
| Code: |
<?php
require_once "HTML/QuickForm.php";
$form = new HTML_QuickForm('frmTest', 'get');
$options = array('language' => 'en' , 'format' => 'Ymd' , 'minYear' => date('Y') - 1, 'maxYear' => date('Y') + 2);
$date_defaults = array(
'Y' => date('Y'),
'm' => date('m'),
'd' => date('d'),
);
$form->setDefaults(array('mydate' => $date_defaults));
$form->addElement('date', 'mydate', 'Choose date', $options);
$form->addElement('submit', 'btnSubmit', 'Submit');
if ($form->validate())
{
// Form is validated, then processes the data
$form->freeze();
$data = $form->exportValues();
$line = sprintf("%04d%02d%02d", $form->mydate['Y'], $form->mydate['m'], $form->mydate['d']);
echo $line . "<br />";
$form->process('process_data', false);
}
else
{
$form->display();
}
function process_data($values)
{
echo "<pre>";
var_dump($values);
echo "</pre>";
}
?>
|
When I process this, the var_dump works fine, but the value submitted for the $line is all zeros.
Last edited by dgs on Wed Jul 09, 2008 1:39 am; edited 1 time in total |
|
| Back to top |
|
 |
dgs
Joined: 13 May 2008 Posts: 20
|
Posted: Wed Jul 09, 2008 1:39 am Post subject: |
|
|
Ok, here is code that works. Now I just need to figure out why in a program that I have created, a date element is not included correctly in the form.
| Code: | <?php
require_once "HTML/QuickForm.php";
$form = new HTML_QuickForm('frmTest', 'get');
$options = array('language' => 'en' , 'format' => 'Ymd' , 'minYear' => date('Y') - 1, 'maxYear' => date('Y') + 2);
$date_defaults = array(
'Y' => date('Y'),
'm' => date('m'),
'd' => date('d'),
);
$form->setDefaults(array('mydate' => $date_defaults));
$form->addElement('date', 'mydate', 'Choose date', $options);
$form->addElement('submit', 'btnSubmit', 'Submit');
if ($form->validate())
{
// Form is validated, then processes the data
$form->freeze();
$data = $form->exportValues();
$Y = $data['mydate']['Y'];
$m = $data['mydate']['m'];
$d = $data['mydate']['d'];
echo "Y: " . $Y . "<br />";
echo "m: " . $m . "<br />";
echo "d: " . $d . "<br />";
$line = sprintf("%04d%02d%02d", $Y, $m, $d);
echo $line . "<br />";
$form->process('process_data', false);
}
else
{
$form->display();
}
function process_data($values)
{
echo "<pre>";
var_dump($values);
echo "</pre>";
}
?> |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|