Welcome Guest, Not a member yet? Register   Sign In
Creating Back & Next for forms
#1

[eluser]eedfwChris[/eluser]
I was wondering if anyone has a solution on how to making Back & Next buttons work...

All I am doing is updating a single row with data, hitting next (or back to goto the previous row). I can make a Next work but I am not entirely sure how to create a Back type function.

Anyone have any pointers or starters? I am guessing the pagination class is kind of out of the question because it isn't designed to do form buttons.
#2

[eluser]Michael Wales[/eluser]
You could use the pagination class, but it's more designed for larger sets of data.

I assume you are returning the ID of the current record, possibly it's a URI segment? I would make 2 methods in my model get_nextID() and get_prevID().

Those two functions would receive the current ID as a parameter, then query the database and return the URL for editing of the corresponding record.

Get it working with the anchor() tags first - ignore buttons, that is prettiness getting in the way of functionality for the time being.

Once you have it working with anchor() tags, then move on to the buttons - which would simply be button tags with some JavaScript hijacking to process the form correctly.
#3

[eluser]eedfwChris[/eluser]
I'm not using form buttons to make anything look "pretty." I am using them because I don't have to "hijack" the thing and force the submit of a form.

But yea, your idea of get_PrevID and get_NextID sound like the way to go...
#4

[eluser]Michael Wales[/eluser]
You can only have one submit button per form - so some sort of hijacking is going to be involved. Whether you dynamically generate the action value of the form for prev/next and hijack for the other one, or your create a hidden field, then update that field on prev/next click, submit the form, and use the value within the hidden field to determine which record will be retrieved and displayed.

Regardless, you are trying to make a form who's action will be either this or that (form/view/1 or form/view/3 - if you are viewing record #2), therefore - some hijacking is mandatory.
#5

[eluser]Crafter[/eluser]
I'm assuming here that you are refreeing to editing Previos/next records from the database.

The simple way is is use a combination of (OFFSET/)LIMIT and ORDER By in your SQL queries.

For example, you know the current id, right?

The next one will be "SELECT * WHERE id > $currentid ORDER BY id LIMIT 1"
The previous one will be "SELECT * WHERE id < $currentid ORDER BY id DESC LIMIT 1"

Of course, if your (bad) luck is like mine, and you would be doing this when there is a user filter search present, then you'll have to carry across your search criteria and add that to your SELECTs.

Regards, Pradesh




Theme © iAndrew 2016 - Forum software by © MyBB