Cakephp Ajax Tutorial - Using Cakephp's Js Helper and jQuery

  Рет қаралды 68,196

andrewperk

andrewperk

Күн бұрын

In this Cakephp ajax tutorial I walk you through building an ajax enabled contact form. We'll use Cakephp's Js helper along with jQuery to do an ajax database submission. Then we write our own jQuery code to do ajax validation using our existing Cakephp model validations.
The source code and sql for this video are now available on my website:
www.andrews-cus...

Пікірлер: 80
@gottalikeit2010
@gottalikeit2010 13 жыл бұрын
Wish I was young again....You are very sharp and clear in your tut's, appreciate it.
@miguelarchersalgado
@miguelarchersalgado 12 жыл бұрын
Thank you so much. This was really helpful. Whenever knowledge is shared like this my faith in mankind gets restored.
@IdiotaIntegral
@IdiotaIntegral 12 жыл бұрын
Your tutorials are great! Please keep the cakephp ones coming, they are the best I found and the 2.x changes are driving me crazy when I try to follow old tuts.
@AbubakerMahmoudshangab
@AbubakerMahmoudshangab 12 жыл бұрын
Andrew Perkins , you are very talented in making difficult things seem easy as a piece of cake. thank you.
@pitocms
@pitocms 10 жыл бұрын
CakePerk is the best teacher for cakephp !!
@Lsakurifaisu
@Lsakurifaisu 12 жыл бұрын
Thankyou for posting this video, not only did it help me understand how to use ajax with the JS helper but it also cleared up some of the confusion I was having with cakePHP. A superb tutorial :)
@d0ngix
@d0ngix 13 жыл бұрын
Thank you for putting this video. It is very much helpful to me as a newbie to cakephp.
@dmays67
@dmays67 11 жыл бұрын
Great tute! Well paced, clear and explained in understandable terms. As a someone very new to CakePHP & JQuery I found this a great help. Look forward to seeing more of these!
@aoporanu
@aoporanu 12 жыл бұрын
Man, this is great, really helped me a lot with my current project. Both parts are great, but the raw jquery without JsHelper at the end is killer!
@adamburgers
@adamburgers 11 жыл бұрын
Great tip, this stumped me for a little while.
@sonbemi
@sonbemi 12 жыл бұрын
Great tutorial. It really helps and accelerates my learning CakePHP
@dermarek8383
@dermarek8383 10 жыл бұрын
Nice tutorial !!! In Cake 2.x you'll have to do some adjustments, especially in the controller to set the Model's data: $this->request->data['Message'][$this->request->data['field']] = $this->request->data['value'];
@mmasukei1213
@mmasukei1213 10 жыл бұрын
Thank you!! jqueryがよくわからなかったので、ひとまずかけました。ありがとうございます!
@BlakMetall
@BlakMetall 12 жыл бұрын
A video like this is what i needed, so i really really say thank you to you. andrewperk. Thanks for your time.
@RightAwayAi
@RightAwayAi 12 жыл бұрын
you can use the same video for cake 2.0 also, I did that and it is working fine
@ucha19871
@ucha19871 13 жыл бұрын
Nice tutorial Andrew
@xtiam57
@xtiam57 13 жыл бұрын
You are the best man! Thank you very much for this tut. Make more CakePHP tuts!
@theredfont
@theredfont 13 жыл бұрын
very helpful. i've downloaded your tutorial and i'll try your example later. thanks man. you rock.
@jameslcasey1
@jameslcasey1 12 жыл бұрын
Andrew, excellent tutorial! Hope to see more.
@sunnyattwal7829
@sunnyattwal7829 11 жыл бұрын
Hi andrewperk, It is owesome..... Thanks
@palmertj1
@palmertj1 11 жыл бұрын
great job it was very useful, Thanks
@savedario
@savedario 11 жыл бұрын
Thanks a lot. Very helpful !
@andrewperk
@andrewperk 12 жыл бұрын
Because just typing the string of 'sending' is not going to select that element so we can fade it in. You need to use javascript to select the #sending element and then use jQuery to fade it in. Try it yourself, exchange out the $this->Js->get('sending') with just the string 'sending'. It wont work.
@petergoodey
@petergoodey 10 жыл бұрын
JsHelper is being discontinued in CakePHP 3.0 - so it's best avoided.
@mbiangacila
@mbiangacila 12 жыл бұрын
thank you very much, this help me and save my time.
@slappy457
@slappy457 13 жыл бұрын
@zoborowi Cheers - though your fix did not resolve my problem.. after some further debugging I found that error.length was always greater than 2, on successful or unsuccessful results.. so after some head scratching, I opened my validate.ctp to find a white space on the second line. Removed it and all functions as it should.
@IslandCave
@IslandCave 12 жыл бұрын
The error you pointed out at about 51 minutes worked for me just fine without duplicating error messages. With the way that you fixed in your video, that caused it to not give me any error messages when you tab out. For the name field anyway. The email and message fields worked just fine the way you had them. Why is that?
@superbeastxj9
@superbeastxj9 11 жыл бұрын
I fixed this by ensuring that only echo $scripts_for_layout; is the function calling scripts in default.ctp. Also, updated cake uses $this->request->data instead of $this->data in messagescontroller's validate_form() function
@bkkmptt
@bkkmptt 12 жыл бұрын
Thank you very much for the great tutorial!
@fenix32
@fenix32 12 жыл бұрын
Great tutorial. But when i click in send with the field empty it draws another form above the original form. How can i fix it?
@literatemonk
@literatemonk 12 жыл бұрын
Very helpful... thank you for doing this.
@lakshijlak
@lakshijlak 12 жыл бұрын
please do this tutorial for cakephp 2 . it would be really helpful. Thanx again..
@faizan101010
@faizan101010 12 жыл бұрын
@aradhyatul put $this->Js->writeBuffer(array('cache' => TRUE)); in the end of form ctp file. And remove it from layout.ctp
@JoeyHauschildt
@JoeyHauschildt 13 жыл бұрын
Thank you! This was very helpful.
@slappy457
@slappy457 13 жыл бұрын
Most complete tutorial on the Js helper in Cakephp to update via AJAX. thanks! Do have a question regarding success callback. My app; success is never called. I can confirm records are being added to the db so it is successful but the call back function is never called. If I put 'success'=>$this->Js->alert('test') .. nothing happens. The 'complete' call back function runs though. Do you have any info on what makes a successful request or not? Maybe it will help me debug. cheers!
@pimienta400
@pimienta400 13 жыл бұрын
Nice tutorial! How could I do to update a select box after changing another one?
@benkjm
@benkjm 13 жыл бұрын
got this to work. Thanks. I noticed that every time I reload the page, the Js helper recreates a new random .js file in app/webroot/js folder. Is there any way to remove these file in cakephp? Also, is there a way to disable the submit button until all of the validation criteria are met? My issue is that for some reason it's still passing the $this->Message->save($this->data) 'if' statement, but it's reloading the "Could not save to database" view in the "success" div... Thanks
@adamburgers
@adamburgers 11 жыл бұрын
Managed to get the 'sending' section to work but I'm not getting any form validations to work - no error messages appear when I tab or click out of the field. Only error I can see (and it doesn't show an error in the webpage itself) is in 'validate_form.ctp' it says "$error seems to be uninitialized" I've encountered this error before but can't seem to work this one out, and I've followed and double-checked through the tutorial. Thanks. Great tutorial nonetheless.
12 жыл бұрын
Thank you for making this tutorial. Just what I needed for my current project. I have a question, is there a way of uploading files via AJAX? What I would like to do is upload an image via AJAX and then display its thumbnail on the same page as the form. I already have the image resizing part setup on the server.
@Mapciooo
@Mapciooo 12 жыл бұрын
Holy fck dude! I love your voice! Also thank you for free and so valuable knowledge!
@BraveStefan
@BraveStefan 11 жыл бұрын
thank you it's helped me
@intune6
@intune6 10 жыл бұрын
I am new to learning cakephp I followed your tutorial, which I like very much, but I cannot get the error messages to show. The code works fine and I don't get any errors in firebug, but no message on blur event? I am using 2.4.5 version of cakephp if that makes a difference?
@d061
@d061 9 жыл бұрын
you absolute monster !! :)
@aradhyatul
@aradhyatul 12 жыл бұрын
Its not even showing the fadein and fadeout effect. I checked the source code and the script is generate but can't see the effects :(
@adamzerner5208
@adamzerner5208 12 жыл бұрын
i'm getting this error and i can't figure out what the problem is Notice (8): Indirect modification of overloaded property PostsController::$data has no effect [APP/Controller/PostsController.php, line 96] note: i tried to apply this tutorial to the previous blog tutorial with the auth component, trying to validate the add action rather than the contact us form this is the line with the problem $this->data['Post'][$this->params['form']['field']] = $this->params['form']['value'];
@adamzerner5208
@adamzerner5208 12 жыл бұрын
at about 38:00, i don't understand why the handleNameValidation code works the way i'm thinking about it is that in order for the div with the id of name-notEmpty to be created, name-notEmpty.length first has to be equal to 0. however, name-notEmpty.length doesn't exist, and thus can't be equal to 0, thus it could never be created. could you help me understand this?
@imeros88
@imeros88 12 жыл бұрын
Hello @andrewperk, Very good job. Until now, I managed to have the same result as you describe, but I have the following problem: What will happen if I press submit and the page needs validation ( eg not valid mail address)? I see that in this case the response returns all the form. In this case then, the response could not be resubmitted if I press submit button again. Have you any idea why this happens? Thanks in advance, Dimitris
@aradhyatul
@aradhyatul 12 жыл бұрын
Hey, I followed the tutorial exactly but its not working.. when I click on the submit button it refreshes and submits the data..no Ajax ! what could be the problem ?
@tonylisanti
@tonylisanti 12 жыл бұрын
@aradhyatul Not sure if this is the same problem that you are having but, for me, I noticed that the js buffer script was not being created on my server. Turns out the permissions for the folder /webroot/js on my server were not set to be written to and buffer script file was never being created. I changed the permissions for that folder to 777 and now the buffer script is being created and the ajax is working. Not sure if that's the best fix but worked for me.
@RakeshKambojVinayak
@RakeshKambojVinayak 11 жыл бұрын
hi andrewpark it's not working when i click on send it create two form with simple validation error
@gunarsekaran
@gunarsekaran 13 жыл бұрын
thanks
@vikramparihar655
@vikramparihar655 11 жыл бұрын
my blur validation not working properly and after submit blank form all field are showing error as we done. but a new contact form is creates automatically flow the first contact form
@adamzerner5208
@adamzerner5208 12 жыл бұрын
at about 14:30... rather than using $this->Js->get(), why not just type in the string of 'sending...'?
@rebirth3X
@rebirth3X 11 жыл бұрын
I've hit upon the same problem where 'succe­ss' isn't displayed on submission yet everything else appears to be working, sending message appears and messages saved in SQL. Any ideas how to solve this problem? I did try your suggestion of adding a path $this->render('/Messages/succe­ss', 'ajax'). I'm using CakePhp 2.2.4
@nishanthanr605
@nishanthanr605 4 жыл бұрын
Watch in 2020
@RakeshKambojVinayak
@RakeshKambojVinayak 11 жыл бұрын
hi andrewpark pls upload video for cron job for mail in cakephp;if it possible give full detail of cron and functionality
@unoLT
@unoLT 13 жыл бұрын
In validation.js why u use $("#name").attr("id") or $("#name").val() ? You can write just $(this).attr("id") or $(this).val(). And then you dont need dublicate your code :)
@Abhisheksehgal297
@Abhisheksehgal297 12 жыл бұрын
Notice (8): Undefined property: View::$Js [APP\views\layouts\default.ctp, line 16] Fatal error: Call to a member function writeBuffer() on a non-object in C:\xampp\htdocs\cakeajax\app\views\layouts\default.ctp on line 16
@lampels2003
@lampels2003 12 жыл бұрын
Great! tut alys..
@andrewperk
@andrewperk 12 жыл бұрын
This video is rather old. Cake does things a little differently now. Use $this->request->data instead. Try it like this: $field = $this->request->data['field']; $value = $this->request->data['value']; $this->request->data['Post'][$field] = $value;
@andrewperk
@andrewperk 13 жыл бұрын
@unoLT Good tip, thank you.
@rebirth3X
@rebirth3X 11 жыл бұрын
What do I do when the username and password fields fulfill the validation rules but, the user doesn't actually exist? I would surely need some response like, 'User unknown, please check your details and try again.'. How do I add this to the Model?
@RamirezZ2083
@RamirezZ2083 11 жыл бұрын
I have the same problem , did you solve it ?
@coxixx
@coxixx 10 жыл бұрын
would you change CRUD in cake php with ajax
@intune6
@intune6 10 жыл бұрын
Also, when I submit the form without any fields entered, I get error messages, and a double form on the page. One right under the other?
@isotonik5ora
@isotonik5ora 10 жыл бұрын
Hi James, I facing same problem with you. SO did you solve the double form on the page yet? please tell me how do you solve it. Thanks.
@intune6
@intune6 10 жыл бұрын
Adam Klasik No. I never solved it. I decided to not use a framework and just dove into learning php and write my own apps from scratch. There is not a lot of documentation on cakephp or tutorials. Seems to me you spend more time learning someone else's framework and the time would be better spent learning how to write your own. This includes code ingniter, yii, and all the rest. I've messed with them all and it's easier to just learn php yourself.
@topprogrammingtv
@topprogrammingtv 10 жыл бұрын
blur is not the correct event "change " is the correct one
@aradhyatul
@aradhyatul 12 жыл бұрын
Hey @andrewperk How can I contact you ? I used the same code from your website but still this thing wont work ! When I click on the submit I am redirected to a blank page, The entries are saved in the database though ! please help !
@RightAwayAi
@RightAwayAi 12 жыл бұрын
include Js helper in the app_controller.php
@CamiloSanchez1979
@CamiloSanchez1979 12 жыл бұрын
Is this 2.0?
@Carlitta87
@Carlitta87 12 жыл бұрын
can u do one where u can send an email?
@ernestojimenez6085
@ernestojimenez6085 12 жыл бұрын
it will be awesome if you translate this to 2.x
@josephmyalla3611
@josephmyalla3611 12 жыл бұрын
any one done similar tutorial using cakephp2
@CodeByNight
@CodeByNight 9 жыл бұрын
Can't believe they still baking this terrible framework.
@mobinshah1
@mobinshah1 9 жыл бұрын
Can't believe you can even type.
@IslandCave
@IslandCave 12 жыл бұрын
Is this also for Ajax 1.3? Because I can't get it to work, I get: Undefined property: View::$Js [APP\views\layouts\default.ctp, line 17]
CakePHP 4 jQuery ajax post request(46).
12:34
Alimon Pito
Рет қаралды 9 М.
Hamster Kombat Season 2 - Hamster Kombat Season 1 Ended | Hamster Kombat Withdrawal Now
10:45
African Giant by Blessing Kolawole
Рет қаралды 222 М.
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 119 МЛН
LIFEHACK😳 Rate our backpacks 1-10 😜🔥🎒
00:13
Diana Belitskay
Рет қаралды 3,3 МЛН
PHP Ajax Introduction Tutorial in Hindi / Urdu
21:27
Yahoo Baba
Рет қаралды 295 М.
Cakephp 2.0 Auth Component Tutorial
54:39
andrewperk
Рет қаралды 79 М.
Get all values from submitted form
0:57
Coding in Public
Рет қаралды 17 М.
Laravel Tutorial Part 5 - CRUD - Retrieving Data with Eloquent
17:41