Welcome Guest, Not a member yet? Register   Sign In
form_hidden bug
#1

(This post was last modified: 06-01-2016, 06:28 PM by obozdag.)

The code below generates duplicate hidden inputs. Because third arg ('id="old_email"') in third row of code is an extra and it is added mistakenly. But this results in duplicate hidden inputs. So is this a bug?

Code:
<?php echo form_open('/user/edit', 'class="form"'); ?>
<?php echo form_hidden('id', '3'); ?>
<?php echo form_hidden('old_email', '[email protected]', 'id="old_email"'); ?>
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>

Print:
<form action="/user/edit" class="form" method="post" accept-charset="utf-8">
<input type="hidden" name="id" value="3">
<input type="hidden" name="id" value="3">
<input type="hidden" name="old_email" value="[email protected]">
<input type="submit" name="submit" value="Submit">
</form>
Reply
#2

No.
Reply
#3

Hi,

The form_hidden helper function does not allow for extra parameters, only field_name and value.
To achieve this you need to use form_input function with an array.

Look just above this you have the documentation for a hidden field with extras.
http://www.codeigniter.com/user_guide/he...form_input
Reply
#4

Think of a form where you are editing things which have the same field name - like a shopping cart that has a Quantity field for each product in the cart. If there are 3 items in the cart, then the Quantity field name is going to be the same for each one. So codeigniter is set up to handle this. If its intentional you put array brackets after the field name like quantity[] and then loop through the form results.
Reply
#5

(This post was last modified: 06-01-2016, 04:41 PM by PaulD. Edit Reason: quick edit )

The shopping cart class is being deprecated, but you can easily create a shopping basket with a simple table. Once you have done that these problems would disappear to a certain extent, as each item in the basket would have its own id or basket_code.

The real difficulty about this is how you implement users that are logged in verses users that are not logged in. You need two ways to identify the users carts, session id and user id. The nice thing is that once they are logged in their baskets are still available to them. The only other thing you would need to add is a mechanism to delete all entries older than say 3 or 6 months.

The shopping cart class can be quirky enough that the first time you use it is a real pain, although in fairness once you get used to it, it is quite nice. I will miss it once it is gone but I think the decision to deprecate it was the right one.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB