Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question validation sample snippet?

    hi,

    I have a form in my mvc

    PHP Code:
    <h1>Update Password <?php echo $model->MemberShipID?></h1>
    <div class="form">
    <?php echo CHtml::beginForm(array('id'=>'updatepwd')); ?>
    <?php 
    echo CHtml::errorSummary($model)?>

    <div class="row">
        <?php echo CHtml::activeLabelEx($model,'WSLoginPassword'); ?>
        <?php echo CHtml::activePasswordField($model,'WSLoginPassword',array('size'=>20,'maxlength'=>50,'id'=>'pwd')); ?>
        <?php echo CHtml::error($model,'WSLoginPassword'); ?>
    </div>

    <div class="row">
        <?php echo CHtml::activeLabelEx($model,'Retype Password'); ?>
        <?php echo CHtml::activePasswordField($model,'WSLoginPassword_repeat',array('id' => 'retypepwd')); ?>
    </div>

    <div class="action">
    <?php echo CHtml::submitButton('Update'); ?>
    </div>

    <?php echo CHtml::endForm(); ?>
    can someone give me a snippet how to use jquery to do the validation on this once the submitButton is clicked, it will check if

    - the 'pwd' field is empty and cannot be empty
    - the 'retypepwd' field should be exactly the same as the 'pwd' field and cannot be empty
    Last edited by capt_nemo777; 12-08-2010 at 09:05 AM.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Post the generated client-side HTML, not the raw server-side PHP.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts
    problem solved, I only know the basic of jquery, but somehow it works, thanks for the reply

    Code:
    <script>
      $(document).ready(function(){
    	$('#updatepwd').submit(function(){
    		if($('#pwd').val() == 0){
    		alert('password cannot be empty');
    		return false;
    		}
    		if($('#retypepwd').val() == 0){
    		alert('retype password cannot be empty');
    		return false;
    		}
    		if($('#retypepwd').val() !== $('#pwd').val()){
    		alert('retype password must be the same with first field');
    		return false;
    		}
    	});
      });
    </script>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •