how to generate a variable and pass it from view to controller? |
[eluser]pistolPete[/eluser]
The hidden input field does not have an id, so you can't use getElementById. html: Code: (...) js: Code: (...) Some general questions: - Why don't you use a javascript library like jQuery? It really simplifies javascript. - What is your script doing at all? Are you calculating prices via javascript? This can easily be changed on the client side!
[eluser]ValdemarDeMatos[/eluser]
Well, I'm starting with this php and javasript thing. So I was needing to make a form that calculates the prices of some products based on the quantity that the user inputs. As I'm not very familiar whith the javascipt frameworks so I hardcode it myself (the way I could). Due to my inexperience I've done it like this. ... This is like a sacrileg, right?
[eluser]ValdemarDeMatos[/eluser]
What do you mean when you say that 'This can easily be changed on the client side'?
[eluser]pistolPete[/eluser]
If you do your calculations in javascript and then send that value to the server, a "hacker" can change the value before it is sent. E.g. he could change the total price to "0" and he would get everything for free. There is a Cart library for CodeIgniter in the svn repository, which you could have a look at: Cart.php
[eluser]TheFuzzy0ne[/eluser]
Basically, you can do your calculations on the client side for customer convenience, but don't assume you're getting the right value back on the server. Always double-check your data. If the user doesn't have JavaScript enabled, the the calculations will not take place either.
[eluser]ValdemarDeMatos[/eluser]
Although this is 'closed' clients circuit, you are obviously right. Is this Cart Class you're showing me, related to this: http://locomotiva-assets.com/user_guide/.../cart.html ?
[eluser]pistolPete[/eluser]
Yes this is the user guide from svn which isn't available on codeigniter.com yet, since 1.7.2 has not been released.
[eluser]ValdemarDeMatos[/eluser]
Well... let's remake it in an all new way! We have to suffer to learn. :blank: I think I'm going to need you again in a near future. I hope i'll be more prepared then. Thank so much pistolPete for your precious advices and for wasting your time with a newbie like me :red: Thank you also TheFuzzy0ne.
[eluser]TheFuzzy0ne[/eluser]
It's only a waste of time if no progress is made, otherwise, it's time well spent. |
Welcome Guest, Not a member yet? Register Sign In |