How to save data in a new column with Post-save helper?

0

Hello everyone,

I'm having troubles with post-save helper. I have a date column and I want to save a year of that date in a separate column, say "year". However, I can't find any examples with such case and can't figure out by myself how to do it :(

Would really appreciate if anyone can help me with the code.

Many thanks, Dasha

asked Sep 10 '10 at 3:02

dashaluna

54

add comment
enter at least 15 characters

3 Answers

1

>Also, I'm not sure which helper to use pre-save or post-save :S

you don't need to save pod twice, so it's better to use pre-save

>Do I have to have column "year" declared in the Pod?

$columns['year']['value'] stands for column you need to fill out with year value - if it has another name, just change 'year' to that name

$column['date']['value'] (i guess it should be $columns) stands for initial date column with 'date' name

answered Sep 10 '10 at 8:37

Fike

208

edited Sep 10 '10 at 8:37

add comment
enter at least 15 characters
0

something like this should help -

$date = $column['date']['value'];
$year = substr($date,0,4);
$columns['year']['value']=$year;

answered Sep 10 '10 at 4:59

Ayush

1

add comment
enter at least 15 characters
0

@Ayush, this doesn't seem to work :( Do I have to have column "year" declared in the Pod? If I do, then it shows up in the add/edit Pod form and I don't want it there.

Also, I'm not sure which helper to use pre-save or post-save :S

answered Sep 10 '10 at 5:17

dashaluna

54

ya...year is the column where you want to store the year and if you don't want to show it in public form then use the hidden attribute on it. check this - http://podscms.org/codex/publicform. – Ayush Sep 12 '10 at 9:02
add comment
enter at least 15 characters