In the Cookbook-master, there is a nice example of ajax-form-validation. But there is a problem as well : the same email can be registered infinitely.
To check whether the subscriber’s email already exists I can use page('events/event')->registrations()->toStructure()->findBy('email', $data['email'])
but how to integrate it ?
It can’t go into plugins/validationForm.php because of error "Can't use method return value in write context".
What would be the sane solution to check whether the email exists already in “Registrations” and to send an error “You’ve already registered” ?
Well, you are free to do what you want. I wouldn’t use that code like this. If correct code throws an error, you have to find out why it throws an error, not use wrong code only because it seems to work.
well… the original code doesn’t use “==”. There’s just
“if($response['success'] = true”.
My injections need a comparison “==”.
in front of you, I’m a newbie, @texnixe. If you find a minute, have a look at the original ajax-form-validation code then compare it with my modifications. I suppose many users will be grateful to you as the check is useful.
Your corrected code didn’t throw any error. Just nothing happens (nowhere) when you press “submit”.
I guess, the debugger ignores ajax/json problems, if any. It’s a php debugger.