Re: Validation messages not showing up on Change Password page

2011-01-09 Thread Amit Badkas
Hi,

Check if the validation errors has any data or not. The code for this will
be something like

if ($this-User-save($this-data)) {
$this-Session-setFlash(__('Your account information has been saved',
true));
$this-redirect(array('controller' = 'users', 'action' = 'view'));
} else {
debug($this-User-validationErrors);
$this-Session-setFlash(__('Sorry, a problem occurred trying to save
your account information. Please, try again.', true));
}

Amit Badkas

PHP Applications for E-Biz: http://www.sanisoft.com



On Fri, Jan 7, 2011 at 10:55 AM, alvinj devda...@gmail.com wrote:

 if ($this-User-save($this-data)) {
  $this-Session-setFlash(__('Your account information has
 been saved', true));
  $this-redirect(array('controller' = 'users', 'action' =
 'view'));
} else {
  $this-Session-setFlash(__('Sorry, a problem occurred
 trying to save your account information. Please, try again.', true));
}


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Validation messages for Ajax calls

2010-07-12 Thread Sam
I do it by having jQuery make a post call when each field is changed-
In this case it sends it only does it if the form has a class ajax.
The post request includes the field id... I do this to make it simpler
to perform the .post callback, although it could be done another way.
The post response returns the error message if there is one, which
jquery inserts into the page.

$(.ajax input:not('.hasDatepicker')).change(function (){
var action = $(this).closest(form).attr(action);
var inputId = this.id;

$(# + inputId).removeClass(form-error form-valid);
$(# + inputId).next(.error-message).remove();
$(# + inputId).addClass(form-check);

$.post(
action,
$(# +inputId ).serialize() + data[Input]
[id]=+inputId,
function (xml){
var message = $(xml).find('message').text();
var inputId = $(xml).find('input').text();

if(message){
$(# + inputId).addClass(form-error);
$(# + inputId).after(div class='error-
message' +message+/div);
} else {
$(# + inputId).addClass(form-valid);
}
},
xml
);
});


I have the action of my form check for an ajax request- if it is it
performs the _validate function

function edit($id = null){
if ($this-RequestHandler-isAjax()  !empty($this-data)){
$this-_validate();
//function will save if validates
}
//rest of code
}


The validate function validates the field. In this case I'm validating
a multiple model field.
function _validate(){

$this-set('inputId', $this-data['Input']['id']);
// Validate the Affiliate, if it's ok, show no
errors. If not ok, show errors
if ($this-Affiliate-create()  $this-Affiliate-
saveAll($this-data, array('validate' = 'only'))) {
$this-set('error', '0');
$this-set('message', '');
} else {
if(isset($this-data['Affiliate'])){
$errorMessages = $this-
validateErrors($this-Affiliate);

}else if(isset($this-data['Contact'])){
$errorMessages = $this-
validateErrors($this-Affiliate-Contact);
} else if(isset($this-
data['AffiliateApplication'])){
$errorMessages = $this-
validateErrors($this-Affiliate-AffiliateApplication);
}

if(isset($errorMessages[0])){
$errorMessages = $errorMessages[0];
}
//$errorMessages = $this-validateErrors();
$this-set('error', '1');
$this-set('message',
array_shift($errorMessages));
}

$this-render('/elements/validation', 'xml');
}

validation.ctp

I return the response as xml, which is parsed by my javascript
function
validation
input?php echo $inputId; ?/input
error?php echo $error; ?/error
message?php echo $message;?/message
/validation





On Jul 12, 12:48 pm, Jonas jonas.sand...@gmail.com wrote:
 Hello,

 I am using Ajax calls to save/remove entries from a database. When
 saving I use validation rules from my Model which works fine (they
 used to be called by a post submit before). Then I used $form-isFieldError 
 to determine which field caused the error in the

 validation. But how do I do this when validating through Ajax?

 Thanks,

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: validation messages

2010-07-09 Thread grigri
Your should just be able to return the string...

function checkCheese(tilsit, caerphilly, cheddar) {
  if (!tilsit) {
return Never at the end of the week, sir. Always get it fresh
first thing on Monday.;
  }
  if (!caerphilly) {
return Ah well, it's been on order for two weeks, sir. I was
expecting it this morning.;
  }
  if (!cheddar) {
return Well, I'm afraid we don't get much call for it around
these parts;
  }
  return true;
}

hth
grigri

On Jul 9, 12:12 pm, emanuele emanuel...@gmail.com wrote:
 Hello pals, I ve my own validation method. The method checks three fields.
 Is there any possibility  to customize the message of error depending on the
 failure condtions? For istance:

 function myfunc(a, b, c) {
 if(!a)
 set a message for a;
 elseif(!b) set a message for b;
 elseif(!c) set a message for c;

 }

 thanks in advance
 --
 Emanuele Gringeri
 Computer Engineer
 University of Pisa
 Be my mirror, my sword and shield

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: validation messages

2010-07-09 Thread Mike Karthauser
you are better doing

function checkCheese($cheese) {
  if ($cheese !='tilsit') {
return Never at the end of the week, sir. Always get it fresh
first thing on Monday.;
  }
  if ($cheese !='caerphilly') {
return Ah well, it's been on order for two weeks, sir. I was
expecting it this morning.;
  }
  if ($cheese !='cheddar') {
return Well, I'm afraid we don't get much call for it around
these parts;
  }
  return true;
}


tbh you should move your validation into your model file and then using
one of the many built in validation rules or rolling your own
http://book.cakephp.org/view/134/Core-Validation-Rules



On Fri, July 9, 2010 12:55 pm, grigri wrote:
 Your should just be able to return the string...

 function checkCheese(tilsit, caerphilly, cheddar) {
   if (!tilsit) {
 return Never at the end of the week, sir. Always get it fresh
 first thing on Monday.;
   }
   if (!caerphilly) {
 return Ah well, it's been on order for two weeks, sir. I was
 expecting it this morning.;
   }
   if (!cheddar) {
 return Well, I'm afraid we don't get much call for it around
 these parts;
   }
   return true;
 }

 hth
 grigri

 On Jul 9, 12:12 pm, emanuele emanuel...@gmail.com wrote:
 Hello pals, I ve my own validation method. The method checks three
 fields.
 Is there any possibility  to customize the message of error depending on
 the
 failure condtions? For istance:

 function myfunc(a, b, c) {
 if(!a)
 set a message for a;
 elseif(!b) set a message for b;
 elseif(!c) set a message for c;

 }

 thanks in advance
 --
 Emanuele Gringeri
 Computer Engineer
 University of Pisa
 Be my mirror, my sword and shield

 Check out the new CakePHP Questions site http://cakeqs.org and help others
 with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.com For more options, visit this group
 at http://groups.google.com/group/cake-php?hl=en




-- 
Mike Karthauser
Managing Director - Brightstorm Ltd

Email: mi...@brightstorm.co.uk
Web: http://www.brightstorm.co.uk
Tel:  07939 252144 (mobile)
Fax: 0870 1320560

Address: 1 Brewery Court, North Street, Bristol, BS3 1JS

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: validation messages problems

2009-05-29 Thread brian

On Fri, May 29, 2009 at 10:52 AM, jrsh...@googlemail.com
jrsh...@googlemail.com wrote:


 I keep getting the following message, after I have clicked 'add' on my
 form, when it is invalid in any way and when a submission is
 successful:

 Not Found
 Error: The requested address '/contacts/add' was not found on this
 server.


Set debug to 2 in core.php. Cake defaults to a 404 when there's an
error and debug is at 0.

 On a successful submission the e-mail is sent, but it still results in
 the above message. I have added a redirect to my controller to
 redirect back to the page, but no error messages are displayed
 accordingly. I have added $form-error('Contact.name').. etc but they
 do not display the messages defined in my model.
 I do not have a view file for the controllers action and I just want
 to call the method then go back to the initial page and display the
 appropriate error messages.

I don't see a redirect in your method. In any case, you want to avoid
doing that because your $validationErrors won't exist if you redirect.
The correct way to handle this is to only redirect when the save is
successful. That way, Cake will redisplay the form otherwise, and
FormHelper will know to display the error messages.

Think of it this way: When the user first browses to /contacts/add
Cake will display the add view, which contains a form. Your save code
will not be parsed because $this-data is empty (or, in your case,
because RequestHandler-isPost() returns false). FormHelper will
create the empty form.

When the form is submitted, RequestHandler-isPost() retrn true and
Cake will run through your save() operations. If that is successful,
your code should redirect somewhere else.

If the save fails, though, your code shouldbe allowed to finish
running therough the controller method. Cake will, in turn, re-display
the form. Because your $validationErrors is not empty, FormHelper
should display the error messages.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Validation messages and redirect issue

2009-05-04 Thread brian

Yes, the redirect is the problem because it forces a new request to
the server. Validation messages are not the same as Session flash()
messages in that they're not saved in the session and available at a
later time.

If you consider a typical action involving a form submission, if
there's no save() (ie. because of invalid data) PHP will run through
the method without reaching a redirect. Because of this, Cake will
redisplay the action's view (the form). And FormHelper, in drawing up
the things its responsible for, will catch and display any validation
error messages. They're just view variables, in other words.

Someone else might have a better idea, but I think the easiest
solution would be to put the messages in the session and display them
in the same manner as session flash messages. That is, go around
FormHelper completely for displaying the errors. The downside is that
the errors won't be displayed inline with the form but, if you're
registration is on the homepage, I'm assuming there are only a couple
of fields. Even if not, it might not be so bad.

So, before redirection, check $this-User-validationErrors and, if
not empty, use $this-Session-flash() to transport it to the next
view. I suppose you'll need to loop through the array and grab
whatever errors are present. Use
die(debug($this-User-validationErrors)) in your action to see how
its laid out.

Does that make sense?

On Mon, May 4, 2009 at 1:07 AM, Eric Martin emarti...@gmail.com wrote:

 I'm having a problem getting validation messages to show up for a
 register/sign-up form. I have the form on the home page, which is
 accessed through a HomeController.

 The register/sign-up form posts to the UsersController, register
 function, which does the save. Regardless of the result, it redirects
 back to the home page but the form validation messages are gone.

 If I move the register/sign-up form to its own url/page, it all works,
 so I'm pretty sure that the redirect is wiping out the validation
 messages.

 Being fairly new to CakePHP, I'd appreciate any suggestions on how to
 make this work.

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Validation messages and redirect issue

2009-05-04 Thread Eric Martin

Thanks brian! I've decided to either just send the user to the user/
register page if an error occurs (which will maintain the messages) or
do as you suggested.


On May 4, 9:05 am, brian bally.z...@gmail.com wrote:
 Yes, the redirect is the problem because it forces a new request to
 the server. Validation messages are not the same as Session flash()
 messages in that they're not saved in the session and available at a
 later time.

 If you consider a typical action involving a form submission, if
 there's no save() (ie. because of invalid data) PHP will run through
 the method without reaching a redirect. Because of this, Cake will
 redisplay the action's view (the form). And FormHelper, in drawing up
 the things its responsible for, will catch and display any validation
 error messages. They're just view variables, in other words.

 Someone else might have a better idea, but I think the easiest
 solution would be to put the messages in the session and display them
 in the same manner as session flash messages. That is, go around
 FormHelper completely for displaying the errors. The downside is that
 the errors won't be displayed inline with the form but, if you're
 registration is on the homepage, I'm assuming there are only a couple
 of fields. Even if not, it might not be so bad.

 So, before redirection, check $this-User-validationErrors and, if
 not empty, use $this-Session-flash() to transport it to the next
 view. I suppose you'll need to loop through the array and grab
 whatever errors are present. Use
 die(debug($this-User-validationErrors)) in your action to see how
 its laid out.

 Does that make sense?

 On Mon, May 4, 2009 at 1:07 AM, Eric Martin emarti...@gmail.com wrote:

  I'm having a problem getting validation messages to show up for a
  register/sign-up form. I have the form on the home page, which is
  accessed through a HomeController.

  The register/sign-up form posts to the UsersController, register
  function, which does the save. Regardless of the result, it redirects
  back to the home page but the form validation messages are gone.

  If I move the register/sign-up form to its own url/page, it all works,
  so I'm pretty sure that the redirect is wiping out the validation
  messages.

  Being fairly new to CakePHP, I'd appreciate any suggestions on how to
  make this work.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---