 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
dgs
Joined: 13 May 2008 Posts: 20
|
Posted: Tue Jul 01, 2008 11:10 pm Post subject: SOLVED: quickform date not showing up |
|
|
I am trying to figure out how to address the date fields. When I print this out, it only shows 6 in the array, not 7. The date field is missing. This is just a snippet of the code.
| Code: |
$opts = array('size' => 20 , 'maxlength' => 255);
// add selection list
$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')
);
$form2->setDefaults(array('mydate' => $date_defaults));
$form2->addElement('date', 'mydate', 'Choose date', $options);
$form2->addElement('select', 'gl_codes', 'GL Codes:', $code->getGlCodes());
$form2->addElement('select', 'jl_codes', 'JL Codes:', $code->getJlCodes());
$form2->addElement('select', 'transaction_type_description', 'Transaction Types:', $trans->getTransType());
$form2->addElement('text', 'hours', 'Billable hours', $opts);
$form2->addElement('textarea', 'description', 'Description', array('rows' => 6 , 'cols' => 40));
$form2->addElement('submit', 'btnSubmit', 'Submit');
$form2->applyFilter('hours', 'trim');
$form2->applyFilter('description', 'trim');
if ($form2->validate())
{
// Form is validated, then processes the data
$form2->freeze();
$data = $form2->exportValues();
echo "<pre>";
var_dump($data);
echo "</pre>";
}
else
{
//$form2->display();
$formsource = $form2->toHtml();
}
| [/code]
Last edited by dgs on Thu Jul 10, 2008 3:34 am; edited 3 times in total |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Wed Jul 02, 2008 7:44 am Post subject: Re: quickform date not showing up |
|
|
| dgs wrote: | | I am trying to figure out how to address the date fields. When I print this out, it only shows 6 in the array, not 7. The date field is missing. This is just a snippet of the code. |
Your code works fine here (I've replaced the method calls for the select elements by simply array() calls), it shows the "mydate" values in the var_dump() output.
Are you sure that you don't some dirty hacks in the lines that haven't shown here? |
|
| Back to top |
|
 |
dgs
Joined: 13 May 2008 Posts: 20
|
Posted: Thu Jul 03, 2008 8:33 am Post subject: Re: quickform date not showing up |
|
|
| mark wrote: |
Your code works fine here (I've replaced the method calls for the select elements by simply array() calls), it shows the "mydate" values in the var_dump() output.
Are you sure that you don't some dirty hacks in the lines that haven't shown here? |
That could in fact be the case. What I am really trying to get a handle on though, is how to assign the Y,m,d variables so that I can put it in a database. I believe it is arranged as a group, and I have not gotten my head around how that works. I wish I could find a book on quickform, it is very powerful, but some of the code snippets leave a lot to be desired.
Thanks again for your help, you are always very helpful.
thanks,
Danny |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Fri Jul 04, 2008 1:58 pm Post subject: Re: quickform date not showing up |
|
|
| dgs wrote: | | What I am really trying to get a handle on though, is how to assign the Y,m,d variables so that I can put it in a database. I believe it is arranged as a group, and I have not gotten my head around how that works. |
You're right, internally are date elements groups of multiple select elements. That's the reason why you have to specify an array with 'Y', 'm', 'd' etc. keys for the setDefaults() call.
After submission you'll also get an array of values back. To insert a date into the database, you could build a string like this:
$date_for_db = $data['mydate']['Y'] . '-' . $data['mydate']['m'] . '-' . $data['mydate']['d'];
If you have also time values, you'll just need to extend this string by the time values in the correct format. |
|
| Back to top |
|
 |
dgs
Joined: 13 May 2008 Posts: 20
|
Posted: Sat Jul 05, 2008 12:17 am Post subject: |
|
|
Thanks, that is what I was looking for. An example is worth a thousand words.
thanks,
Danny |
|
| Back to top |
|
 |
dgs
Joined: 13 May 2008 Posts: 20
|
Posted: Wed Jul 09, 2008 2:40 am Post subject: |
|
|
Ok, this is the code that broke it. I run the server that it runs on, so I don't have to worry about magic_quotes, anyway, but I am not sure how this works. This code came from the book by Sitepoint, The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition. I just commented it out, and it works. If no-one comments for a few days, that understands why this caused a problem, I will mark this solved as it is, I am just curious why.
thanks,
Danny
| Code: | <?php
/**
* Checks for magic_quotes_gpc = On and strips them from incoming
* requests if necessary
*/
if (get_magic_quotes_gpc())
{
$_GET = array_map('stripslashes', $_GET);
$_POST = array_map('stripslashes', $_POST);
$_COOKIE = array_map('stripslashes', $_COOKIE);
}
?> |
|
|
| 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
|
|