wishbone Posted June 3, 2022 Share Posted June 3, 2022 Hi, php mailer mail($emailTo, "subject", $msg, "From: $form[email]"); how can I format the date output? the input field: <input type="date" id="termin1" name="termin1" value="$form[termin1]" placeholder="Wunschtermin"> the sanitizer: 'termin1' => $sanitizer->date($input->post->termin1), the php mail message call: "Wunschtermin: $form[termin1]\n" . With no format defined, unix timestamp is being outputted. If format defined in the sanitizer, always "20.10.2007" is outputted, no matter which date was picked: 'termin1' => $sanitizer->date($input->post->termin1, "d.m.Y"), if input field is formated, unix timestamps is being outputted <input type="date" id="termin1" name="termin1" value="$form[termin1]" placeholder="Wunschtermin" format="d.m.Y."> How do I do this? Thx ! Link to comment Share on other sites More sharing options...
wishbone Posted June 4, 2022 Author Share Posted June 4, 2022 Finally, I have to give up on processwire. It's not for designers. THe community is very vivid, helpful, friendly and brave, but it seems that my problems aren't what is expected. For my current project, I'm hopeless.? Link to comment Share on other sites More sharing options...
Jan Romero Posted June 4, 2022 Share Posted June 4, 2022 Hi, as per the docs you can specify the return format in $sanitizer->date(), just not quite the way you have done it (https://processwire.com/api/ref/sanitizer/date/). This should do the trick: $sanitizer->date($input->post->termin1, ['returnFormat' => 'd.m.Y']); 1 Link to comment Share on other sites More sharing options...
wishbone Posted June 4, 2022 Author Share Posted June 4, 2022 thank you so much for looking into this, Jan, but I get a syntax error ^^ form output: Quote Fatal Error: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given in \wire\core\WireDateTime.php:415 ? Link to comment Share on other sites More sharing options...
Jan Romero Posted June 4, 2022 Share Posted June 4, 2022 Huh, sorry, I thought ProcessWire would figure out the arguments automatically, since their types are distinct. It usually does that. Try passing null in the second argument: $sanitizer->date($input->post->termin1, null, ['returnFormat' => 'd.m.Y']); (Sorry, I’m on vacation, no code formatting on mobile) Anyway, as I understand it, the first parameter is the format you expect the incoming value to be. A sanitizer’s job is generally to make sure the input conforms to some expectation. In this case you don’t care what format the input is, so you don’t tell it your expectation and it will just try to make any valid date out of the input. Additionally you specify the returnFormat to get a pre-formatted string back (this is not always desired because often dates need to be used in calculations or be checked against additional logic). Be aware you might still get null if the input can’t be made into a valid date. Also, if the input is in an ambiguous format, it may get parsed in an unexpected way (in fact, sometimes it seems to default to the current date). But this shouldn’t be a problem because AFAIK browsers all send YYYY-MM-DD when a date input is used. It’s just to say that it’s usually good practice to specify the input format. 1 Link to comment Share on other sites More sharing options...
wishbone Posted June 4, 2022 Author Share Posted June 4, 2022 hurraahhh! that works! thx thx thx project saved. ? How could I have possibly found that out by myself ^^ 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now