"Failed to parse time string" with custom Form template

tcranford

Member
I'm having an issue with dates in a custom form template that doesn't appear when using the standard bootstrap form template. The date field has a single "notempty" validation rule. When I enter a mm-dd-yyyy date (no time component) and select "Save" it throws the following error:
DateTime::__construct(): Failed to parse time string (05-14-1966) at position 0 (0): Unexpected character

I suspect that there is some javascript event that fires for the standard bootstrap form template that doesn't fire for my custom form template because when using the standard template and I hit the "Save" button I briefly see the format of the date string go to a yyyy-mm-dd H:i format. This behavior doesn't happen for the custom form template.

I need fresher eyes on this, mine are currently crossing...

TIA!

I'm running J! 3.7 and F 3.6. My sites profile has been updated as well with specifics on replicating the problem.
 

Attachments

  • date prob - 2017-05-21_8-58-32.jpg
    date prob - 2017-05-21_8-58-32.jpg
    61.6 KB · Views: 55
Can you either turn "bust JS" off (Fabrik global options), or provide backend login instructions so I can do it. Unfortunately I can't debug JS when bust is on, as the debugger doesn't recognize files as being the same from page load to page load.

-- hugh
 
Nope, bust is still enabled, and even though I can now get into the backend, I can't turn it off because my login isn't a super admin, so no access to the global options.

-- hugh
 
Sorry hugh, I just overlaid the fabrik db from development so clobbered my setting. You've now got SA and Burst is off.
Thanks!
 
Last edited:
OK, the problem is that you've moved a bunch of the parts of the form outside of the <form>...</form> tags. Including some of the elements, and the submit buttons.

bad_dom.png

As you can see in that DOM inspection, the form itself is in a g-content div, but then you have elements outside of the form, and the hidden fields and actions outside of the g-content div.

So a) the submit button never gets seen, submit events don't fire, so our submission code doesn't run (which among other things formats the date), and b) none of those elements outside the form (or the hidden fields, which are critical) will get submitted.

You need to restructure your template so everything is inside the form tags.

-- hugh
 
As I look closer at this it appears to be some strange PHP output buffering deal (possibly nested output buffering). My custom default.php template file has all of the appropriate content and form controls inside the form tag however when executed I see the output you noted above...some content outside the form tag. One difference I have from the default bootstrap template is that I wasn't calling the "loadTemplate" with group(s) function. This simply so that I could have better control with placement of the individual groups within the form. Inside that loadTemplate function is some output buffering going on which should be completely encapsulated within that call.

In any case I'm new to the Joomla templating concept so I clearly am missing something important. So...I've attached my template file in hopes some kind soul can point out the error of my evil ways!

Code:
defined('_JEXEC') or die('Restricted access');

function renderElement(&$element) {
  echo '<div class="control-group ' . $element->containerClass . (trim($element->error) !== '' ? ' error' : '') . ' span3">';
  echo '<label>' . $element->label . '</label>';
  echo '<div class="controls">';
  echo '<div class="fabrikElement">';
  echo $element->element;
  echo '</div>';
  echo '</div>';
  if (trim($element->error) !== '') :
  echo '<div class="fabrikErrorMessage help-inline text-danger">';
  echo '<i class="icon-warning " data-isicon="true"></i>';
  echo $element->error;
  echo '</div>';
  endif; 
  echo '</div>';
}

$form = $this->form;
$model = $this->getModel();
$groupTmpl = $model->editable ? 'group' : 'group_details';
$active = ($form->error != '') ? '' : ' fabrikHide';

if ($this->params->get('show_page_heading', 1)) : ?>
  <div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
  <?php echo $this->escape($this->params->get('page_heading')); ?>
  </div>
<?php
endif;

if ($this->params->get('show-title', 1)) :?>
<div class="page-header">
  <h1><?php echo $form->label;?></h1>
</div>
<?php
endif;

echo $form->intro;
?>
<form method="post" <?php echo $form->attribs?>>
<?php
echo $this->plugintop;
?>

<div class="fabrikMainError alert alert-error fabrikError<?php echo $active?>">
  <button class="close" data-dismiss="alert">?</button>
  <?php echo $form->error; ?>
</div>

<div class="container-fluid nav">
  <div class="span6 pull-right">
  <?php
  echo $this->loadTemplate('buttons');
  ?>
  </div>
  <div class="span6">
  <?php
  echo $this->loadTemplate('relateddata');
  ?>
  </div>
</div>

<?php
$myPerson = $this->groups['Watch'];
$perElements = $myPerson->elements;
$myVehicle = $this->groups['WatchVehicle'];
$vehElements = $myVehicle->elements;
$myCustExp = $this->groups['WatchCustExp'];
$custExpElements = $myCustExp->elements;
$myCustExp2 = $this->groups['WatchCustExp2'];
$custExpElements2 = $myCustExp2->elements;
$myCustExp3 = $this->groups['WatchCustExp3'];
$custExpElements3 = $myCustExp3->elements;
$myCustExp4 = $this->groups['WatchCustExp4'];
$custExpElements4 = $myCustExp4->elements;
$myCustExp5 = $this->groups['WatchCustExp5'];
$custExpElements5 = $myCustExp5->elements;

/* Watch group */
?>
<fieldset class="<?php echo $myPerson->class; ?>" id="group<?php echo $myPerson->id;?>" style="<?php echo $myPerson->css;?>">
  <?php
  if ($myPerson->showLegend) :?>
  <legend class="legend"><?php echo $myPerson->title;?></legend>
  <?php
  endif;

  if (!empty($myPerson->intro)) : ?>
  <div class="groupintro"><?php echo $myPerson->intro ?></div>
  <?php
  endif;?>

  <div class="row-fluid" style="margin-bottom: 20px;">
  <div class="span3""><label><?php echo $perElements['id_type']->label; ?></label><?php echo $perElements['id_type']->element; ?></div>
  <div class="span3""><label><?php echo $perElements['id_state']->label; ?></label><?php echo $perElements['id_state']->element; ?></div>
  <?php
  renderElement($perElements['id_num']);
  renderElement($perElements['finance_again']);
  ?>
  </div>
  <div class="row-fluid" style="margin-bottom: 20px;">
  <?php
  renderElement($perElements['cust_first_name']);
  renderElement($perElements['cust_middle_name']);
  renderElement($perElements['cust_last_name']);
  renderElement($perElements['cust_dob']);
  ?>
  </div>
  <div class="row-fluid" style="margin-bottom: 60px;">
  <?php
  renderElement($perElements['cust_city']);
  renderElement($perElements['cust_state']);
  renderElement($perElements['cust_zip']);
  ?>
  </div>

<?php
  if (!empty($myPerson->outro)) : ?>
  <div class="groupoutro"><?php echo $myPerson->outro ?></div>
  <?php
  endif;
?>
</fieldset>

<?php
/* WatchCustExp' Group */
?>
<fieldset class="<?php echo $myCustExp->class; ?>" id="group<?php echo $myCustExp->id;?>" style="<?php echo $myCustExp->css;?>">
  <?php
  if ($myCustExp->showLegend) :?>
  <legend class="legend"><?php echo $myCustExp->title;?></legend>
  <?php
  endif;

  if (!empty($myCustExp->intro)) : ?>
  <div class="groupintro"><?php echo $myCustExp->intro ?></div>
  <?php
  endif;
  ?>

  <div class="container-fluid">
<?php
  echo '<div class="control-group ' . $custExpElements['cust_exp']->containerClass . (trim($custExpElements['cust_exp']->error) !== '' ? ' error' : '') . ' span3">';
  echo '<label class="ceLabel">' . $custExpElements['cust_exp']->label . '</label>';
  echo $custExpElements['cust_exp']->element;
  if (trim($custExpElements['cust_exp']->error) !== '') :
  echo '<div class="fabrikErrorMessage help-inline text-danger">';
  echo '<i class="icon-warning " data-isicon="true"></i>';
  echo $custExpElements['cust_exp']->error;
  echo '</div>';
  endif; 
  echo '</div>';
?>  
  <div class="span3"><label class="ceLabel"><?php echo $custExpElements2['cust_exp2']->label; ?></label><?php echo $custExpElements2['cust_exp2']->element; ?><label class="ceLabel2"><?php echo $custExpElements3['cust_exp3']->label; ?></label><?php echo $custExpElements3['cust_exp3']->element; ?></div>
  <div class="span3"><label class="ceLabel"><?php echo $custExpElements4['cust_exp4']->label; ?></label><?php echo $custExpElements4['cust_exp4']->element; ?></div>
  <div class="span3"><label class="ceLabel"><?php echo $custExpElements5['cust_exp5']->label; ?></label><?php echo $custExpElements5['cust_exp5']->element; ?></div>
  </div>

  <?php
  if (!empty($myCustExp->outro)) : ?>
  <div class="groupoutro"><?php echo $myCustExp->outro ?></div>
  <?php
  endif;
?>
</fieldset>

<?php
/* WatchVehicle Group */
?>
<fieldset class="<?php echo $myVehicle->class; ?>" id="group<?php echo $myVehicle->id;?>" style="<?php echo $myVehicle->css;?>">
  <?php
  if ($myVehicle->showLegend) :?>
  <legend class="legend"><?php echo $myVehicle->title;?></legend>
  <?php
  endif;

  if (!empty($myVehicle->intro)) : ?>
  <div class="groupintro"><?php echo $myVehicle->intro ?></div>
  <?php
  endif;
  ?>

  <div class="container-fluid" style="margin-bottom: 20px;">
  <?php
  renderElement($vehElements['vin']);
  renderElement($vehElements['car_year']);
  renderElement($vehElements['car_make']);
  renderElement($vehElements['car_model']);
  ?>
  </div>
  <div class="container-fluid">
  <?php
  renderElement($vehElements['plate_num']);
  ?>
  </div>

  <?php
  if (!empty($myVehicle->outro)) : ?>
  <div class="groupoutro"><?php echo $myVehicle->outro ?></div>
  <?php
  endif;
?>
</fieldset>


<div class="row-fluid">
  <div class="control-group fabrikElementContainer plg-internalid fb_el_watch___id fabrikHide span2" style="display:none"><?php echo $perElements['id']->label; ?><div class="controls"><div class="fabrikElement"><?php echo $perElements['id']->element; ?></div></div></div></div>
  <div class="control-group fabrikElementContainer plg-field fb_el_watch___dealer_id fabrikHide span2" style="display:none"><?php echo $perElements['dealer_id']->label; ?><div class="controls"><div class="fabrikElement"><?php echo $perElements['dealer_id']->element; ?></div></div></div></div>
  <div class="control-group fabrikElementContainer plg-date fb_el_watch___created_at fabrikHide span2" style="display:none"><?php echo $perElements['created_at']->label; ?><div class="controls"><div class="fabrikElement"><?php echo $perElements['created_at']->element; ?></div></div></div></div>
  <div class="control-group fabrikElementContainer plg-date fb_el_watch___updated_at fabrikHide span2" style="display:none"><?php echo $perElements['updated_at']->label; ?><div class="controls"><div class="fabrikElement"><?php echo $perElements['updated_at']->element; ?></div></div></div></div>
  <div class="control-group fabrikElementContainer plg-user fb_el_watch___uid fabrikHide span2" style="display:none"><?php echo $perElements['uid']->label; ?><div class="controls"><div class="fabrikElement"><?php echo $perElements['uid']->element; ?></div></div></div></div>
</div>

<?php
if ($model->editable) : ?>
<div class="fabrikHiddenFields">
  <?php echo $this->hiddenFields; ?>
</div>
<?php
endif;

echo $this->pluginbottom;
echo $this->loadTemplate('actions');
?>
</form>
<?php
echo $form->outro;
echo $this->pluginend;
echo FabrikHelperHTML::keepalive();

TIA
-Troy
 
Most likely is that you have mismatched divs, where you haven't closed one. Try running your page source through validator.w3.org. It'll generate a lot of warnings, but if you play with the settings to reduce the trivial warnings, it should help you spot in closed tags.

Sent from my HTC6545LVW using Tapatalk
 
Yup. I ran your page through http://validator.w3,.org, and you have a number of issues with the structure, things like "End tag div seen, but there were open elements.", "Unclosed element form." etc.

One instance I can see right away is where you render some hidden elements, and you have one too many closing divs on each, for example:

Code:
  <div class="control-group fabrikElementContainer plg-internalid fb_el_watch___id fabrikHide span2" style="display:none"><?php echo $perElements['id']->label; ?><div class="controls"><div class="fabrikElement"><?php echo $perElements['id']->element; ?></div></div></div></div>

... which, if you lay it out with indentation to make things clearer, you can see it ...

Code:
<div class="control-group fabrikElementContainer plg-internalid fb_el_watch___id fabrikHide span2" style="display:none">
    <?php echo $perElements['id']->label; ?>
    <div class="controls">
         <div class="fabrikElement">
             <?php echo $perElements['id']->element; ?>
         </div>
    </div>
</div>
</div>   <------  OOOOPS

Basically, any time you see the markup on the page go weird like this, with things not inside divs or other structural elements that they should be, it's because you've messed up the structure and not balanced your open/close tags.

And one way to avoid that when writing code is to always indent, so it's visually obvious when you haven't balanced your structure tags.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top