4 Replies Latest reply: May 13, 2009 3:41 PM by Phil_W RSS

    Spry textfield validation with XHR submit

    Phil_W Community Member

      Hi,

       

      I have a form called register' here at http://www.thehmc.co.uk/forum2/register.asp

       

      It has Spry validation on the textfields, with some validation on the the field contents changing as well as form submit. If I amend a field you can see it dynamically validating the format for instance on the email field.

       

      I register an event listener for button with id="reg" being clicked which submits the form to a server side page. A callback function registerResponse deals with the response from my server side page.   When I click the button to register it does not validate the Spry validation fields.  How can I achieve this -  is there something I can call within the register function before my submit or do I need to amend my button event to simulate the normal form submit behavior somehow?

       

      function register()
      {
          Spry.Utils.submitForm('register', registerResponse,false);
         
      }
      function registerResponse(req)
      {
          var mytext = req.xhRequest.responseText
           if (mytext = "success")
                {
              Spry.$$('#registration').addClassName('mynone');
              var success = '<p>You have successfully registered</p>';
              success = success + '<p>If approved you will receive an email within a few days. To complete your registration you will need to click the link in the email to activate your forum account.</p>';
              success = success + '<p>Once your account is activated you will be able to post and reply in the forum. Why not edit your profile and choose an avatar or add a signature for your posts</p>';
              success = success + '<p>Thank you for registering</p>';
              success = success + '<p>Hertfordshire Mountaineering Club</p>';
              Spry.Utils.setInnerHTML('regSuccess', success);
               }
              else
              {
                 var failure = 'You have failed to register';
                 Spry.Utils.setInnerHTML('regResponse', failure);
            }
          
              
              
      }

       

      Don't worry about actually registering if you visit the page - the server side page doesn't actually update the database yet. So click away

       

      Thanks

       

      Phil