| Post |
|
Guest
| Rob 8:16 pm November 30, 2011
| |
|
|
CF2 Version v12.2
WordPress 3.1.3
PHP version 5.1.6
I've searched all over and not quite found this answered anywhere. So far, I'm successfully outputting submitted forms onto a Page, using the excellent built-in API functions and example code from the help and these forums.
But I want to include a column in my HTML table with the submission date. Simple, right? But I haven't found any examples of this. Bear in mind that I have no date custom field in my form. I'm referring to the submission date/time that CF already records and displays in the admin Tracking page.
The latest copy of the help PDF talks about a variable called "sub_date", but this doesn't seem to output anything. My code looks like this:
<?php
$signature_array = get_cforms_entries('Statement signing',false,false,'sub_date',false,'desc');
// $signature_array = get_cforms_entries();
echo '<table>';
echo '<tr><th>Name</th><th>Title</th><th>Website</th><th>Date</th></tr>';
foreach( $signature_array as $e )
{
/*
echo '<tr><td>'.$e['data']['Your Full Name'].'</td><td>'.$e['data']['Title'].'</td><td>'.$e['data']['Website'].$e['data']['sub_date'].'</td><tr>';
*/
echo '<tr>
<td>'.$e['data']['Your Full Name'].'</td>
<td>'.$e['data']['Title'].'</td>
<td>'.$e['data']['Website'].'</td>
<td>'.$e['data']['sub_date'].'</td>
<tr>';
}
echo '</table>';
?>
|
|
|
Guest
| Rob 10:13 pm December 1, 2011
| |
|
|
Well, though this thread isn't yet approved, I've made some headway. I dug into the plugin's catacombs and found in file "lib_aux.php" there are functions for extracting the IP and date. They are:
cf_getip()
gmdate('Y-m-d H:i:s', current_time('timestamp'))
Put into my output code:
echo '<tr>
<td>'.$e['data']['Your Full Name'].'</td>
<td>'.$e['data']['Title'].'</td>
<td>'.$e['data']['Website'].'</td>
<td>'.gmdate('Y-m-d H:i:s', current_time('timestamp')).'</td>
<tr>';
However, these are only returning my IP and date, not the date of submission. So close now!
|
|
|
Guest
| Rob 7:40 pm December 9, 2011
| |
|
|
|
|
Admin
| Oliver Munich, Germany posts 6237 6:57 pm December 19, 2011
| |
|
|
can you try $e['data']['date'] instead?
|
|
|
|
|
Guest
| Rob 6:42 pm December 22, 2011
| |
|
|
Oliver said:
can you try $e['data']['date'] instead?
Thanks for your help, Oliver! So I tried your suggestion, both lowercase and uppercase "date" field names. No data gets output at all with that attempt.
:(
|
|
|
Guest
| Ashwan 1:54 am December 23, 2011
| |
|
|
It should be $e['date'] or $e['timestamp'] in your foreach {} loop
Use timestamp to get a UNIX timestamp which you can format using PHP's date() function.
|
|
|
Admin
| Oliver Munich, Germany posts 6237 7:33 am December 23, 2011
| |
|
|
Either one should work really.
If you look at the function's code in lib_aux.php:
function get_cforms_entries(…){
…
$cfdata[$d->id]['date'] = $d->sub_date;
$cfdata[$d->id]['timestamp'] = $d->rawdate;
…
}
It shows that both keys are set.
To be a 100% sure how your array is construed, try printing the entire array:
print_r( $e );
|
|
|
|
|
Guest
| Rob 9:48 pm December 23, 2011
| |
|
|
Ashwan said:
It should be $e['date'] or $e['timestamp'] in your foreach {} loop
Ok, the date is now working! My mistake was in thinking that the date was embedded into each entry. Below now shows each form's submission date:
echo '<tr>
<td>'.$e['no'].'</td>
<td>'.$e['data']['Your Full Name'].'</td>
<td>'.$e['data']['Title'].'</td>
<td>'.$e['data']['Website'].'</td>
<td>'.$e['date'].'</td>
<tr>';
Is there a way to show the submission number? Or perhaps a way to output the total number of submissions?
|
|
|
Guest
| Rob 6:35 am December 24, 2011
| |
|
|
Never mind, found it. The correct field name is "id". So this works nicely:
echo '<tr>
<td>'.$e['id'].'</td>
<td>'.$e['data']['Your Full Name'].'</td>
<td>'.$e['data']['Title'].'</td>
<td>'.$e['data']['Website'].'</td>
<td>'.$e['date'].'</td>
<tr>';
Now to get the sort working and I'll be set.
|
|
|
Guest
| Ashwan 11:34 am December 24, 2011
| |
|
|
Oliver said:
If you look at the function's code in lib_aux.php:
function get_cforms_entries(…){
…
$cfdata[$d->id]['date'] = $d->sub_date;
$cfdata[$d->id]['timestamp'] = $d->rawdate;
…
}
It shows that both keys are set.
Yup, but your first reply to Rob told him to use $e['data']['date'] which doesn't exist. :) It's $e['date']
|
|
|
Admin
| Oliver Munich, Germany posts 6237 12:07 pm December 24, 2011
| |
|
|
Ashwan said:
Oliver said:
Yup, but your first reply to Rob told him to use $e['data']['date'] which doesn't exist. :) It's $e['date']
you're right, must have been pre-xmas tunnel vision ;)
|
|
|
|