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 8580027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:44:20+00:00 2026-06-11T20:44:20+00:00

I want to set up a functionnality on user registration: user can enter a

  • 0

I want to set up a functionnality on user registration: user can enter a coupon code that has been previously generated and stored in a table. The field appears along with the user registration form. If they enter a code that doesn’t exist, the form shoudln’t validate, an error message should appear telling them the code is invalid.
What is the best practise to achieve this?

My problem is that the coupon field isn’t linked to the User entity.
I can check the coupon code’s validity with ajax and only validate the form if the code exists or the field is empty.
But if I proceed like this, how can I access the coupon code data in my RegistrationFormHandler? The aim is to give special priviledge to User who entered a valid code.

Is this a good way to do at all?

  • 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-11T20:44:21+00:00Added an answer on June 11, 2026 at 8:44 pm

    In your form add a text field with a false property_path:

    $builder->add('coupon', 'text', array('property_path' => false));
    

    Validate it either using ajax or a custom event subscriber (I would prefer the latter). The in your controller It should be enough to check if the form is valid:

    if('POST' === $request->getMethod()) {
        $form->bindRequest($request);
    }
    
    if('GET' === $request->getMethod() && $form->isValid()) {
        // Here both user and coupon are valid
        $coupon = $form->get('coupon')->getData();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run drupal 6 and want to code this functionality: after the user filled
I have been reading a lot about test-driven development and decided that I want
I want to set up a search functionality on my web site. The user
I have a user control that generates a series of arrow buttons. I want
I want to use GNU screen in such a way that the user doesn't
EDIT It appears the user has to enter some data for his profile, otherwise
I want to write a static utility class which only has a set of
I have a group of checkboxes that I only want to allow a set
I want to create a layout that has small panels at the top and
I want to create a set of buttons that would work and feel very

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.