Skip navigation
Currently Being Moderated

Spry validation Date form with default value error

Jun 20, 2012 3:09 PM

Tags: #cs4 #cs5 #help #adobe #php #cs5.5 #dreamweaver #javascript #code #cs6

The below spry validation form was created with DW CS6

 

I created an HTML form and posted it with PHP to a MySQL database.  One of the form lines is to enter a date.  That line is using a "out of the box" sprytextfield data validation without modification to any of its CSS or JS:

 

HTML

<span id="sprytextfield1">

          <label for="servComDate">Starting Date?</label>

          <input type="text" name="servComDate" id="servComDate">

          <span class="textfieldRequiredMsg">A value is required.</span>

               <span class="textfieldInvalidFormatMsg">Invalid format.</span>

          </span>

 

<script type="text/javascript">

var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {hint:"00/00/0000", format:"mm/dd/yyyy"});

</script>

 

On submission, the form value is captured via PHP and the date format is converted to a MySQL format before entering it into the database.

 

PHP

$servComDate = date("Y-m-d", strtotime($_POST['servComDate']));

 

All of the above is working perfectly.

 

Now, I have created a different page with an HTML form to edit the information.  First, the PHP pulls the field from the database and converts it from the MySQL format back to the format used in the above sprytextfield it was created in.

 

PHP

$servComDate = strftime("%m/%d/%Y", strtotime($row["servComDate"]));

 

Then the HTML form is populated with the existing value

 

HTML

          <span id="sprytextfield1">

               <label for="servComDate">If the Service is Coming Soon, do you know when the service will start being offered?</label>

               <input type="text" name="servComDate" id="servComDate" value="<?php echo $servComDate; ?>">

             <span class="textfieldRequiredMsg">A value is required.</span>

             <span class="textfieldInvalidFormatMsg">Invalid format.</span>

          </span>

 

When pre-populating the form with the existing value it displays with the proper format in the input box, but shows these "errors":

 

      value is required. Invalid format.

 

As I said above, I have not changed any of the CSS or JS that is loaded with the Spry textfield, so I did not include that here.

 

I am obviously doing something wrong with pre-populating a Spry textfield with a default value.

 

What is the correct what to have a default value on a Spry Validation Date Textfield?

 

Thanks in advance!

 
Replies
  • Currently Being Moderated
    Jun 21, 2012 12:35 AM   in reply to TheBitBug

    Make sure that in the Edit page the constructor looks like

    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {hint:"00/00/0000", format:"mm/dd/yyyy"});

    The following works fine for me

    <span id="sprytextfield1">

    <label for="text1"></label>

    <input type="text" name="text1" id="text1" value="<?php echo strftime("%m/%d/%Y", strtotime($row_Recordset1['UserRegistrationDate'])); ?>">

    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>

    <script type="text/javascript">

    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {hint:"00/00/0000", validateOn:["blur"], format:"mm/dd/yyyy"});

    </script>

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 6:25 PM   in reply to TheBitBug

    I know the feeling, nearly as good as you know what, although at my age, that's only going from memory.

     

    Thank you for your feedback.

     

    Gramps

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points