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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:12:55+00:00 2026-06-18T05:12:55+00:00

I have the following HTML form: <form method=post action=register.php class=form-horizontal id=form-registrazione> <fieldset> <div class=modal-header>

  • 0

I have the following HTML form:

<form method="post" action="register.php" class="form-horizontal" id="form-registrazione">
          <fieldset>
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                <h3 id="registrazioneLabel">Registrazione</h3>
              </div>
              <div class="modal-body">
                <div class="control-group">
                      <!-- Username -->
                      <label class="control-label">Username</label>
                      <div class="controls">
                        <div class="input-prepend">
                          <span class="add-on"><i class="icon-user"></i></span>
                          <input name="username" class="span2" placeholder="Leonardo" id="username" type="text">
                        </div>
                        <div id="username_msg"></div>
                      </div>

                    </div>



                <div class="control-group">
                      <!-- Email -->
                      <label class="control-label">Email</label>
                      <div class="controls">
                        <div class="input-prepend">
                          <span class="add-on"><i class="icon-envelope"></i></span>
                          <input name="email" class="span2" placeholder="mario@rossi.com" id="email" type="email">
                        </div>
                        <div id="email_msg"></div>
                      </div>
                    </div>

                <div class="control-group">
                      <!-- Password -->
                      <label class="control-label">Password</label>
                      <div class="controls">
                        <div class="input-prepend">
                          <span class="add-on"><i class="icon-key"></i></span>
                          <input name="password" class="span2" placeholder="Password" id="password" type="password">
                        </div>
                        <div id="password_msg"></div>
                      </div>
                    </div>

                <div class="control-group">
                  <!-- Conferma password -->
                  <label class="control-label">Conferma password</label>
                  <div class="controls">
                    <div class="input-prepend">
                      <span class="add-on"><i class="icon-key"></i></span>
                      <input name="repassword" class="span2" placeholder="Password" id="repassword" type="password">
                    </div>
                    <div id="repassword_msg"></div>
                  </div>
                </div>

              </div>
              <div class="modal-footer">
                <input type="submit" value="Registrati" class="btn btn-primary">
                <button class="btn" data-dismiss="modal" aria-hidden="true">Chiudi</button>
              </div>
        </fieldset>
      </form>

And the following Javascript Validation code:

<script>
    // SI ACCETTANO SOLO USERNAME CON CARATTERI ALFANUMERICI, SPAZI, TRATTINI E UDNERSCORE
    jQuery.validator.addMethod("alphanumeric", function(value, element) {
        var stringa = new String(value);
        stringa = stringa.replace(" ", "");
        stringa = stringa.replace("-", "");
        stringa = stringa.replace("_", "");
        return this.optional(element) || /^[a-zA-Z0-9]+$/.test(stringa.valueOf());
    });

    // SCRIPT CHE CONVALIDA IL FORM DI REGISTRAZIONE
    $(document).ready(function(){
        $('#form-registrazione').validate({
        rules: {
          username: {
            minlength: 6,
            maxlength: 15,
            alphanumeric: true,
            // L'USERNAME NON DEVE ESSERE GIA' USATO
            remote: {
                url: "do_action.php?action=username_used",
                type: "post",
                async: false,
                data: {
                  email: function() {
                    return $("#username").val();
                  }
                }
            },
            required: true
          },
          email: {
            required: true,
            email: true,
            // L'EMAIL NON DEVE ESSERE GIA' UTILIZZATA
            remote: {
                url: "do_action.php?action=email_used",
                type: "post",
                async: false,
                data: {
                  username: function() {
                    return $("#email").val();
                  }
                }
            },
          },
          password: {
            minlength: 8,
            required: true
          },
          repassword: {
            minlength: 8,
            required: true,
            equalTo: "#password"
          }
        },
        messages: {
            username: {
                required: "Scegli il tuo nome utente.",
                minlength: "Inserisci almeno almeno 6 caratteri.",
                maxlength: "Inserisci meno di 15 caratteri.",
                alphanumeric: "Si accettano soltanto caratteri alfanumerici, spazi, trattini e underscore.",
                remote: "L'username &egrave; gi&agrave; utilizzato da un altro giocatore, per favore scegline un altro."
            },
            password: {
                required: "Imposta una password.",
                minlength: "La password deve essere lunga almeno 8 caratteri.",
            },
            repassword: {
                required: "Conferma la tua password.",
                minlength: "La password deve essere lunga almeno 8 caratteri.",
                equalTo: "Le due password non combaciano."
            },
            email: {
                required: "Inserisci un indirizzo email.",
                email: "L'indirizzo email inserito non &egrave; corretto.",
                remote: "L'email &egrave; gi&agrave; utilizzata da un altro giocatore, puoi utilizzare un'altra email oppure <a href='recover.php'>recuperare i dati del tuo account</a>."
            }
        },
        highlight: function(label) {
            $(label).closest('.control-group').removeClass("success").addClass('error');
        },
        success: function(label) {
            label
                .addClass('valid')
                .closest('.control-group').addClass('success');
        }
      });
    });
</script>

The code works, it also checks if username/email are already used. The problem is that if the error string is too long the text goes out of the page (no new lines), so I created four divs in which I would like to place the error messages so the text will make new lines when needed.

My goal is to display every username error in the div “#username_msg”, every email error in the div “#email_msg”, etc. I tried many things, I searched and Google, I also tried the showErrors method but I couldn’t fix my problem… so here I am.

I am using Twitter Bootstrap and the form is displayed correctly into a Modal (http://twitter.github.com/bootstrap/javascript.html#modals).

Thanks in advance!

  • 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-18T05:12:56+00:00Added an answer on June 18, 2026 at 5:12 am

    Quote: “My goal is to display every username error in the div #username_msg,
    every email error in the div #email_msg, etc.

    You cannot put each individual message within their own uniquely tagged div. You can, however, put the messages inside of a div element instead of a label. However, this will not solve your issue any better than simply using CSS to format the label element.

    http://docs.jquery.com/Plugins/Validation/validate#toptions

    errorElement, String, Default: “label”

    Use this element type to create error messages and to look for
    existing error messages. The default, “label”, has the advantage of
    creating a meaningful link between error message and invalid field
    using the for attribute (which is always used, no matter the element
    type).

    As per comments, using div since the OP wants the message to display under the input element.

    errorElement: "div"
    

    Then you can control how the div displays using CSS…

    div.error {
        width: 200px; // whatever you need
        white-space: normal;  // to ensure wrapping despite twitter bootstrap css
    }
    

    Working Demo: http://jsfiddle.net/f9Ut4/1/


    EDIT:

    Explanation – there was a rule, white-space: nowrap, within the Twitter Bootstrap CSS file that was inherited by your div.error which told its text content to not wrap. The rule I suggest above, white-space: normal, simply reverses the nowrap rule and since it has a more specific target, div.error, it will take precedence over the rule within the Twitter Bootstrap CSS.

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

Sidebar

Related Questions

I have a html file like following: <form action=/2811457/follow?gsid=3_5bce9b871484d3af90c89f37 method=post> <div> <a href=/2811457/follow?page=2&amp;gsid=3_5bce9b871484d3af90c89f37>next_page</a> &nbsp;<input
I have the following fom: form id=login_form class=fancy_form action=@Url.Action(Logon, Account) method=POST> <div class=bl_label> Eneter
I have a form with the following HTML below: <form id=course_edit_form name=course_form action=/courses/save method=post>
I have a simple html form that looks like the following <form action=search.php method=get>
I have an included object's form: <form method=post class=object_form id=event-core-form action={% url save_event_core_data event.id
I have the following html code: <form> <table> <tbody> <tr> <td> <span>Quantity<span class=pull-right>3</span> <input
I have a html/php form like the following: Form 1: Apple options: -big -medium
I have the following code: <% using (Html.BeginForm(AddComment, Comments, FormMethod.Post)) { %> <div id=New_Comment>
I have the following form: @model Teesa.Models.SearchModel @using (Html.BeginForm(Index, Search, FormMethod.Get, new { id
I have following Situation, Server A sends some data (HTML form) to server B,

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.