Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8590935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:24:35+00:00 2026-06-11T23:24:35+00:00

I added validation to a form and found that in some cases it is

  • 0

I added validation to a form and found that in some cases it is losing the invalid data I am feeding it and saving 0s instead. The output at the bottom shows that if I post the latitude as ‘zzzzzz‘, which is clearly not a number nor between -90 and 90, the form is declared as valid and saved with the value 0.

How can that happen given that I have declared the input must be a number?

ProxyType.php buildForm():

$builder
        ->add('siteName', null, array('label' => 'Site name'))
        ....
        ->add('latitude', 'number', array('label' => 'Latitude'))
        ->add('longitude', 'number', array('label' => 'Longitude'))
        ....
    ;

ProxyController.php createAction:

    ....
    $postData = $request->request->get('niwa_pictbundle_proxytype');
    $this->get('logger')->info('Posted latitude = '.$postData['latitude']);

    $form    = $this->createForm(new ProxyType(), $entity);
    $form->bindRequest($request);

    if ($form->isValid()) {
        $this->get('logger')->info('Form declared valid : latlong ('.$entity->getLatitude().','.$entity->getLongitude().')');
        ....

validation.yml:

Acme\PictBundle\Entity\Proxy:
properties: 
    longitude:
        - Min: { limit: -180 }
        - Max: { limit: 180 }
    latitude:
        - Max: { limit: 90 }
        - Min: { limit: -90 }

Output:

[2012-09-28 02:05:30] app.INFO: Posted latitude = zzzzzz [] []
[2012-09-28 02:05:30] app.INFO: Form declared valid : latlong (0,0) [] []
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:24:36+00:00Added an answer on June 11, 2026 at 11:24 pm

    What’s happening is you’re not using a number validation, but rather bounding the form field to be a number, thus when you bind the request to the form it transforms the string into a number (which for any string which starts without a number will be 0). A form field being a number means it expects to come as a number, or rather, there should be some validation in the front-end of such thing or the front-end should not allow a non-number to be set.

    I think what you seem to want is a form field of type text with a number validation.

    For actual validation use the constraint type (additional to your min and max values).

    http://symfony.com/doc/current/book/validation.html

    http://symfony.com/doc/current/reference/constraints/Type.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple html form that I've added validation to using the JQuery
I have a form with multiple fields that I'm validating (some with methods added
I am using jquery validation plugin for form validation. I have added a custom
I use jQuery form validation plugin to validate some form fields. As for now
I have added some javascript in html page for input validation.same page is working
I'm trying to create a form validation. I added @user.errors.add_to_base TEST to my controller,
I am trying to add some validation for my registration form, but i can't
We have HTML form which will allow french alphabets. So we have added validation
I have a simple form like below that I have added the jQuery validations
I've tried setting up a form validation that would ensure that at least 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.