View Full Version : Resolved validation sample snippet?

12-07-2010, 04:10 AM

I have a form in my mvc

<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 class="row">
<?php echo CHtml::activeLabelEx($model,'Retype Password'); ?>
<?php echo CHtml::activePasswordField($model,'WSLoginPassword_repeat',array('id' => 'retypepwd')); ?>

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

<?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

12-07-2010, 01:17 PM
Post the generated client-side HTML, not the raw server-side PHP.

12-08-2010, 09:05 AM
problem solved, I only know the basic of jquery, but somehow it works, thanks for the reply

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;