if empty => take today's date
if empty => take today's date
i would need an if else issue.
my code works as long the user inputs an date for 'post_dup', otherwise stops with the alert: "An SQL error occurred: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'post_dup' cannot be null"
in this case editor should take today's date. can anyone help me out with the correct syntax within my existing code.
thx a lot
// Vars
$date_sql = 'Y-m-d H:i:s'; // 2019-12-31 23:59:00 siehe php.net/manual/de/function.date
$datedate = 'd/m/Y'; // 31/12/2019 editor field => format:'DD/MM/YYYY'
$datetime = 'd/m/Y - H:i'; // 31/12/2019 - 12:12 editor field => format:'DD/MM/YYYY - HH:mm'
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
$db->sql('set names utf8');
$editor = Editor::inst(
$db, 'alle_post',
'alle_post.post_idn' /* Primary Key */
)
->fields(
Field::inst('alle_post.post_dup')
->validator(Validate::dateFormat($datetime))
->getFormatter(Format::datetime( $date_sql, $datetime))
->setFormatter(Format::datetime( $datetime, $date_sql)),
);
$editor
->debug(true)
->process($_POST)
->json();
This discussion has been closed.
Answers
A set formatter is the way to do this. You can add a condition to check for an empty value and if so return the current date from the function, otherwise return the date submitted.
Allan
thx allan, i tried your answer but i don't get it. how would be the exact syntax in my case. i'm sorry, but i always struggle with this things.
Is this to be mixed with the existing set formatter though? If so you'd need to call the existing formatter:
I think should do it.
Allan
Allan your second solution gives me an Parse error: syntax error, unexpected '?'
Delete one of the question marks from Allan's example.
thx a lot tangerine. that helped
Oops - sorry. Edited my post to fix that. Thanks for picking that up @tangerine.
Allan
Hi @allan
Nobody's perfect but somebody try to.
Bob
@tangerine. your solution helped me out with new entry, but now the update doesn't work anymore. can you provide me the right syntax for the combination of both.
When you do the update, is it not submitting the existing value from the client-side and thus it would be using that value rather than
date('c')
?Worth noting that you can only have one
setFormatter
on a field, so line 11 will overwrite line 8 in the above code. It won't cause an error, but line 8 is redundant.Allan
i know that i can only use one setFormatter. what i would need is the right syntax for the combination of both.
so when there is no date input (new entry) then take today's date otherwise use the transmitted value. in other words i would need for the second setFormatter above the extension for updating data.
I don't quite understand I'm afraid. The code you show above in lines 11 to 15 looks correct to me. When there is a value submitted it will format it into ISO8601. Otherwise if there is no value submitted (insert or edit, it applies to both) then the current date would be used.
I'm not quite clear if that isn't want you are looking for, or if it is and it isn't working? If it isn't working, what is happening, as the code above looks like it should be doing that.
Allan
http://live.datatables.net/suquzuri/1/edit
by update i get an error
<b>Notice</b>: Undefined variable: datetime in <b>...editor-alle_zzzz-ssp.php</b>
<b>Notice</b>: Undefined variable: date_sql in <b>...editor-alle_zzzz-ssp.php</b>
You need to change the Editor Ajax from a string to:
Otherwise it won't be sending the
webx_idn
parameter when you create, edit or delete.Allan
this do not change anything.
leads to an SyntaxError
is there a way, where i can hire one of you guys ?
i would open an ftp-account to an testserver. iM sure you would solve this and a few other things within a litte time. of course i would pay for this.
i would love to work with editor, cause its so fast and fun editing data but now i spend weeks on some problems.
Like you need to add a comma to the line before to separate the options. Note the comma at the end of line 2 in Allan's code snippet. If you aren't able to resolve the syntax error then post your whole Datatables init code so we can take a look.
Kevin
@kevin - i did already post the code here
http://live.datatables.net/suquzuri/1/edit
Does that example show the changes you made that are causing the syntax error?
I was mistaken above, that change is to the Editor config. Please post your full Editor config.
Kevin
I'm on my phone at the moment so a little limited, but did you replace the
ajax
option in your Editor config with the block I gave above? Simply adding thedata
function isn't enough. You need theajax
option to be an object withurl
anddata
options.If that doesn't fix it, then yes, send me a PM with server details and I'll take a look.
Allan
thx allan - i will send you an pm the next days. happy new year to all kind supporters!
@allan - thx i did send you an PM with details.
Hi,
Many thanks for the PM and apologies for the delay in replying to you there. I've just done so now though.
Regards,
Allan