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

  • SEARCH
  • Home
  • 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 6827571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:16:52+00:00 2026-05-26T22:16:52+00:00

I would like to do something roughly analogous (but not exactly identical) to the

  • 0

I would like to do something roughly analogous (but not exactly identical) to the following: I want to create a Person content type, which has an SSN field. I would like to store the SSN field as an integer, but allow the user to input the number as 123-45-6789. This means that before validation triggers, stating that “123-45-6789” is invalid input, I would like to remove the dashes and treat this as an integer.

I’ve tried to use both a #value_callback function, as well as a non-default validation function. The problem then is that although I can force the value to be validated, the unchanged value is what is passed to the db for insertion, which fails. In example, this means that although I can force “123-45-6789” to be recognized by Drupal as “123456789”, the database is still being passed “123-45-6789”, which of course fails.

The one obvious solution would be altering this via client side javascript, before the value is even submitted to the webserver. I would strongly prefer to avoid this route.

  • 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-05-26T22:16:53+00:00Added an answer on May 26, 2026 at 10:16 pm

    Apologies if I’ve misunderstood but you should just be able to do something like this:

    function my_validation_handler(&$form, &$form_state) {
      if (passes_ssn_validation($form_state['values']['SSN'])) {
        // Changing the value in $form_state here will carry on over to the submission function
        $form_state['values']['SSN'] = convert_to_db_format($form_state['values']['SSN']);
      }
      else {
        form_set_error('SSN', 'The SSN was invalid');
      }
    }
    

    Then you’d attach that validation function using $form['#validate'][] = 'my_validation_handler' in either your form build or form_alter function.

    Hope that helps

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

Sidebar

Related Questions

In jquery that is. I would like something that works as the success-pararameter, but
I would like to do something like the following with spark. <viewdata model=IList[[string]] />
I would like to use something like the following: SELECT city FROM cities WHERE
I would like to do something like this: abstract class Foo { public function
I would like to do something like this in HTML5 where I have something
I would like to recreate something like this if ( arg1 || arg2 ||
I would like to run something like: select * from table where field in
I would like do something like that. list_of_urls = ['http://www.google.fr/', 'http://www.google.fr/', 'http://www.google.cn/', 'http://www.google.com/', 'http://www.google.fr/',
I would like to do something like this i.e., use wild card characters in
I would like to convert something like: <property name='aoeu' value='a,o,e,u'/> to: <path id='ueoa'> <pathelement

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.