Categories > TinyButStrong general >

how can i do form retry using (also) date formating ?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: kle_py
Date: 2010-08-24
Time: 16:16

how can i do form retry using (also) date formating ?

Hi again,

I am using in cases, the same form template for adding registers, but also for editing an existing one !.
When i have a date field, the date formating comes very handy like:
<input name="where[fecha_doc]" value="[blk2.fecha_doc;noerr;frm='dd/mm/yyyy']" size="10">

When the form is filled incorrectly, i would like to show the same form again, using the POST variables received to fill the form values again - so the user can see what she/he had entered before.

However..
it doesn't work for me on the date fields :( .
When i had entered in the form initially: '19/07/2010'
it will show me (for the re-try): 31/12/1969,

i can simulate the same effect adding a line in tbs_us_examples_prmfrm.php:
$my_form_date_str = '19/07/2010';

and in tbs_us_examples_prmfrm.htm:
<tr class="back-special2">

<td>dd/mm/yyyy</td>

<td>my date: [var.my_form_date_str;frm='dd/mm/yyyy']</td>

</tr>


I would like to keep using the TBS-formating option, to make sure the date is interpreted correctly.
Is there a way to use the POST (string)-variable again direcly, or would i have to think of a format conversion of this variable before merging it again ?

Thanks

Klemens
By: TomH
Date: 2010-08-24
Time: 19:58

Re: how can i do form retry using (also) date formating ?

Hmmm... very interesting...

I don't have the precise answer - but I love the problems you find kle_py

The TBS frm= parameter is being used against the raw (db) unixtimestamp or similar - so the return form the form is illegall for the same var frm process.

Only a workaround from me -- a hidden FORM field holding the raw/original unixtimestamp. If the user changes the date them you might be stuck using PHP to process that return string back to a unixtimestamp and compare to the original.

PHP's "strtotime()" function will recognize many english textual date/time descriptions - so that may be useful processing the user entry

Please post back the 'real' solution!

ATB
TomH
By: Skrol29
Date: 2010-08-25
Time: 01:40

Re: how can i do form retry using (also) date formating ?

Hi,

Maybe you can concatenate two TBS fields: one which is the formated date if the entry is correct or empty string if the entry is wrong, and a second one which is empty string if the entry is correct, and the post data if the entry is wrong.
Someting like:
value="[var.date_ok;frm='dd/mm/yyyy'][var.date_err]"
 
By: kle_py
Date: 2010-08-25
Time: 16:20

Re: how can i do form retry using (also) date formating ?

Hmm,

My initial idea of a workaround was using my form-validation routine, which (besides validating) returns an array with copy of the relevant POST variables. In this context i planned to classify:
if ($db_fieldtype[$fieldname] == 'DATE' || $db_fieldtype[$fieldname]  == 'TIMESTAMP'){
  if (strtotime(str_replace('/', '-', $_POST[$fieldname])) !== False){
    $retry_form[$fieldname] = str_replace('/', '-',$_POST[$fieldname]);
    // trying to de-format the value
  }
} else {
    $retry_form[$fieldname] = $_POST[$fieldname];
}

however Your proposed approach seems more universal (maybe i will have some other cases of special formating..), so i might use:
if ($db_fieldtype[$fieldname] == 'DATE' || $db_fieldtype[$fieldname]  == 'TIMESTAMP'){
    $retry_form[$fieldname . '_post'] = $_POST[$fieldname];
} else {
    $retry_form[$fieldname] = $_POST[$fieldname];
}

Thank You