How can i edit data by click href without ajax jquery |
Hello guys thanks for some help in yesterday now i have little problem here is simple demo http://codepen.io/sidaurukfreddy/pen/LpGzjW
Please clcik edit and submit it automatically hide. i have been success for edit form by using jquery and ajax but i can't show to users when form errors cause after submit the div will be hide, am not experts in jquery ajax but little bite know it, i want to make the form look like edit form php buth put the edit form in same position like demo, so here is my real script using jquery view to edit click Code: <div class="col-md-4 box-2-add"> Edit form Code: <div class="inner-3"> Thanks for any support or comment
Hi,
When I am doing something similar I use the normal form validation on my ajax post url, but set the validation errors to : Code: $this->form_validation->set_error_delimiters('Error: ', ''); I also use CSRF protection so don't forget to post the relevant hash codes in your JS post as well. If there is an error I just echo the validation_errors(); or echo the required response, which might just be a simple 'ok' or it might be some relevant HTML to be inserted somewhere. Then in the JS I check the response of the ajax call for error or not like this: Code: var response = theResponse.substring(0,5); That means that following an Ajax call I can deal with a form error or a correct form post result however I want. I often have three tests, an additional one to test if the user is logged in or if the login has expired too, as well as testing if the user is authorised or not. These have responses of their own for testing like 'Login' if re-login required or 'xAuth' if they are not authorised to do that action. Hope that helps, Best wishes, Paul.
oh i'm still don't get it, please guide me in codepen.io or fiddle by your ways or is there any ways to keep this form show after click edit form by using pure php
Thanks
It is hard to do a fiddle with it because of all the dependencies and CI itself of course.
This is how I would do it. 1. Browser shows information plus a link to edit info in a container div. 2. On clicking the link, js prevents normal link action, sends an ajax request to the server. 3. The server (ie now on CI), gets the html form via a view, and returns it to the browser ajax request. 4. The javascript collects the response, and replaces the HTML in the container div, with the form data. It also adds a click event to the submit/save button of the form. 5. When the user hits the save button, another js function (assigned to the submit button previously) collects the form data, and posts it via ajax back to the server for processing. 6. The server processes the posted form data using all the normal form validation in CI. It processes the data however you want it to and on success, returns the HTML, to repopulate the container div with the amended information. -- now there are several ways to approach this next bit. --- 7a. The javascript function collects the returned HTML. Here you can display the information as is if you want. So if an error has occured from the processing of the form, the view from 6 includes an error message, plus the original information, or the form, whatever you want. 7b. The javascript tests the response (in my previous answer I suggested using substr to test the first five characters) and if error, just adds error message to the already displayed form. If no error, then display the response directly because it will be the original data. 7c. The javascript tests for a response, if error, gets the form again through another ajax call, if not, gets the data again through another ajax call This all seems very complicated the first time you do it, but once you get it working, inline editing is really powerful. But you have to have your javascript, your server side processing, and your HTML all working perfectly. There are lots on online tutorials too: http://phppot.com/php/php-mysql-inline-e...uery-ajax/ http://w3lessons.info/2014/04/13/html5-i...uery-ajax/ http://www.smarttutorials.net/inline-edi...bootstrap/ You can google for lots more I hope that helps. Best wishes, Paul. |
Welcome Guest, Not a member yet? Register Sign In |