Welcome Guest, Not a member yet? Register   Sign In
How to Submit textarea comment on Enter key?
#11

[eluser]boltsabre[/eluser]
Quick thought:

1. Get the entire functionality working 100% correct without JS (ie, form submits, inserts data to the DB and redirects to correct controller after the db insert).
2. Then start to implement the JS code incrementally. The JS code above that we talked about ONLY submits the form in the normal "php" way when the user clicks enter. So... you should still see data being written into your DB. Correct, can you see the new data in your DB?
3. If you can see the new data, but the page doesn't change, as you implied in your last post, I imagine that it is because when your form validation passes and you insert your data you are using
Code:
"this->load->view('....')"
Instead of "redirect()". Correct? If so, the reason that you're not seeing any new data on the page (even though it was successfully inserted into your database) is because using the $this->load->view just reloads the same view you had before the DB insert. You need to use "redirect" to force a page refresh (thus a new DB "get all comments" call or whatever you have).

4. Okay... so you don't want this, you want it to dynamically display the new data without a page refresh yes? In which case, this is where you'll have to start using AJAX. I'd look online for some CI/AJAX tutorials and run through them, they'll help you get started.

Let me know if any of the above was incorrect.
#12

[eluser]Prullenbak[/eluser]
Quote:If so, the reason that you’re not seeing any new data on the page (even though it was successfully inserted into your database) is because using the $this->load->view just reloads the same view you had before the DB insert.

That's true, but he should see a change in the address bar, since the form submit (with the regular submit button) sends him to the url comment/addComment. From the code that's visible here, The view with the form is not loaded in that same function, so this form submission will be visible in the address bar.

Otherwise, this would mean the form is broken (i.e. the submit button also doesn't work)
and the problem is not in the jQuery after all Smile

#13

[eluser]boltsabre[/eluser]
True true... perhaps it is best if the OP could post the entire code block, the full controller, the full view (with the JS)...




Theme © iAndrew 2016 - Forum software by © MyBB