Fields depending on other fields issue - drupal

I am using Drupal 6.28 with Webform 6.x-3.18. I have a multi-step form setup. Some of my fields only show up if you select a radio button. In this particular instance this is a registration form and one of the questions is "Will you be bringing a guest?". If they select yes, then some additional fields drop down pertaining to their guest. So this works great. They can submit the form and everything works. The problem is, if they go back into their form to edit it and decide to go solo and now they are NOT bringing a guest, the guest fields disappear from the form as expected, but the data is still there behind the scenes and specifically in the database. So now when we go to run reports on some specific guest fields, those fields are throwing our reports off because the data is still there in the dB as if they are bringing a guest even though they are not now.
Can anyone think of the best place to handle this issue? Should I make a custom module that hooks into the webform somehow and catches for it and resets all the guest fields? I just don't know the best place to handle this.
THANKS

You could have some logic on the submission of the data. If it is the first time they are submitting (not already in DB), go forward as planned. If the data already exists, do a before and after compare on that field in question. If it toggled off you can clear your DB spots for that user.
You could also have something in the form code, so if that radio button is not checked, always insert some blank/null/however you handle it into the DB. This way, it is always writing in those fields as blank even if the data was there before (if you go ahead and rewrite that entire row in the DB anyway).

Related

Is it possible to do paging (numbered) with firebase?

I started a project with firebase. Everything was perfect until it came to the paging section. But I was disappointed about paging. Please help me. Now I will write what I want to do.
There are 100 posts. I'll show 25 on each page.so this means 4 pages.When the user wants to move to the fourth page while on the first page, I want the data of the second and third pages not to be downloaded, only the data of the fourth page to be downloaded. one more example. when the user goes to "https://example.com/posts/page-3" I only want the posts on the third page to be fetched.
Is it possible to do this?
Your question does not specify if you are using Realtime Database or Firestore, but the answer is the same for both of them - it's not possible to do pagination using numeric offsets. In order to request a page of data that starts anywhere after the first item, you are required to know something about that item, or the one that comes right before it. If you don't know anything about that item, you have to start from the beginning, then work you way forward. That's how cursor-based pagination works.
With Firestore pagination, this why the API requires you to pass a DocumentSnapshot to start from, or field values from that document.

How to maintain session in different tabs of same browser?

My website is used to administer customer accounts. If I access CustomerA's account through the website then open a new tab and access CustomerB's account the session holding the customer ID updates to think I'm now working on CustomerB. Then if I click back to CustomerA's tab and start editing that page I am in fact editing the database record for CustomerB. This has happened and caused all sorts of problems so I need to find a fool proof way of stopping it. I don't want to put the customer ID in the URL as this will make it open to abuse.
Session is not a place to hold information like this exactly because of problems you're describing. You need to pass customer ID along with the page itself (either in hidden field or in url), so when you post back the form, it exactly knows what are you trying to do. Session won't protect you nor add any extra security. You need to determine if the user has correct permissions either way, so you should focus on this aspect.

Drupal Multi-step form breaks with node save

I have a custom multi-step form that I add to certain node type content via hook_nodeapi. It is working great, with one exception.
During testing, I've found that when I am in mid-form (say, step 2 of 6) and update the node in another browser tab, my form reverts to step 1 when I try to proceed to the next step. Similarly, when an AHAH event occurs, I get an error and the form disappears altogether. The error suggests there is a problem with retrieving the form from cache after a node update, as it's not able to retrieve the form parameters.
Have you encountered this behaviour before, and/or do you have any suggestions on how I might go about fixing it? It isn't a huge problem as these nodes likely won't be updated too often on the production side, but it would still be a significant nuisance to those it does affect.
Edit: Thanks for your response. Unfortunately I can't contain this form within a block. It must be within the node content itself. Upon further testing I noted that other users thankfully aren't affected. It is only the user that updates the node while in mid-form that is affected. As this is extremely unlikely to happen on the production site, the impact of such an occurrence would be minor, and I have no time at the moment to explore this further, I'm going to move on with this behaviour unexplained for now. But if anyone can point out why this is occurring, I'd appreciate it.
Well, have just tried your situation based on multistep form described here - http://zgadzaj.com/basic-drupal-multipart-form-example-with-previous-and-next-buttons - but put in the block and displayed on node page, and even if I edit this node in a different tab, I still can navigate between all form steps on the original tab, keeping all already submitted values. So I'd say it all probably depends how your form is being built...

asp.net Post/Request/Get question about validation

I'm trying to figure out a logical and quick way to implement the "PRG" design style in a small site I'm doing, and I'm finding an issue I can't think of a good way to solve.
I have a form. It has 2 fields (first and last name). When the user submits the form, I check to make sure that they have data in them before I save it to the database. If they do not, then I show them a nice little error message and leave what little they have entered still in the form.
However, in order to correctly implement PRG, as I understand it, I would have to validate on postback, determine there is an error, then redirect the user to the same page but via get, not post, which would then eliminate any kind of scary message "you are about to resubmit the contents of a form to the server, which can have unintended consequences..." etc if the user reloaded the page.
How can I redirect the user back to the same page and still save their already entered values in the form fields?
I mean, I could pass all the values in the Querystring, but for complex forms this would become very difficult and messy. I could store the values in Session, but that would still be messy, and a good way to bring a webserver to its knees on a busy site.
What do you, my fellow web programmers, do?
As you note, by redirecting, you will lose the data they have entered unless you go through some QueryString gyrations. You are really defeating one of the nice features of asp.net by doing this - the form values are all preserved for you, so that if the page needs to be redisplayed after a post with errors, most of the work is done for you. Why do you want to use a PRG design? What benefit do you expect to get that standard asp.net form handling doesn't give you?

Architecture question involving search & session state

I have a grid with several thousand rows that can be filtered and sorted. On each row you can click a details button, which will bring you a new page with detailed information about the page. Because this is a button, you can't middle click or right click and open in a new tab. In addition, when clicking back you lose your filters and search results.
To solve this problem, I considered the following: Switch the buttons to links, and when filtering and searching, use get instead of post requests. This way, you could switch to new pages with a right click or middle click, and if you did follow a link normally, back would work properly.
This change was not made however. We were asked add a 'next result / previous result' set of buttons on the details page, that would allow you to navigate. While not an elegant solution, it would at least work.
I proposed adding querystring parameters to the details page, that would regenerate the search query based on filter, and allow you to get the next and previous results in code.
A team member took issue with this solution. He believes that it is a waste of server resources to re-query the database. Instead, a solution was proposed to add session variable that included a list of results. You could then use that to navigate.
I took issue with that because you can't have multiple tabs open without breaking navigation, and new results aren't appended to the list in real time. Also, if you worried about optimization, session would be the last thing to use since it eats memory and prevents server replication... unless you store the results back in the database.
What's the best solution?
Session doesn't sound like a winner, won't scale with lots of users.
Hitting the database repeatedly does seem unnecessary, but it depends on the cost - how many users, how often would they refresh/filter and what is the cost of that query?
If you do use querystrings you could cache the pages by parameter.
What about some AJAX code on that button to retrieve details - leave the underlying grid in place and display details in a div/panel or a new window/tab.

Resources