Quantcast
Channel: Tagged with repeater - Plugin Support
Viewing all articles
Browse latest Browse all 160

Repeater field not updating users properly from front end

$
0
0

Hi, I've recently stumbled upon an interesting problem...

I've recently written a menu into a site I'm making in which users can sign up to events from the front end. I've created a back end menu for events with a repeater field so that the organizer of these events can sign site users up. There is also the front end menu in which users can sign up or cancel attendance.

My problem comes when I try to update the users repeater field from the front end with an update_field() function. These are the specific types of error:

On Adding a new user -

  • If I create an array of user IDs, array_push a new user to the end, then put this array into the update_field it adds a new user, but cuts the new array element down to one digit. For example: $initial_array = [5, 33] $update_array = [5, 33, 14] $array_returned_after_update = [5, 33, 1] Another example: [12, 63, 22, 41] -> [12, 63, 22, 4] This seems like very curious behavior to me. I can't see anything that I might be doing wrong, is it a bug?

  • Also, if there are no users and I run update_field it doesn't work. It doesn't add anything at all.

On removing a user:

  • I array_splice() the current user out of an array of user IDs, then run update_field. This works, except when there is only one other user in the event. Then it has the same problem. I don't get to remove the 2nd user, but it reduces the second user to one digit. An example: $before_removing_user = [22, 19] $after_removing_user = [22, 1] Three would be fine: $before_removing_user = [22, 8, 19] $after_removing_user = [22, 8] It's just two that doesn't work.

Does anyone have any idea what's going on? I was wondering that perhaps I should use something other than just an array of IDs to update, but when I try to enter other data (such as an array of user objects) it saves it all as serialized data.

I really don't know what to do to fix this, can anyone help?

I've included a template file which has the functionality that I'm talking about.

Thanks, Dan


Viewing all articles
Browse latest Browse all 160

Trending Articles