I have been struggling to find a solution to this issue for some time now. Basically I have a View that has a field at the top where the user enters a payment amount. I then have 2 forms for 2 different payment methods. The first method is payment via card where card details are entered. The second is payment via a registered account where an account number is entered. When the user submits either form I need to also submit the payment amount from the field at the top of the view.
Currently I have implemented this using just a single form using a ViewModel which has 3 properties (sub models), the PaymentAmount Model, the PaymentCardDetais Model and the AccountDetais Model. The problem with this is that on submission, all model fields in the viewModel get validated. Obviously the user is going to always enter an amount but will only enter either card details OR account details. I'm not sure if this is the best way to implement this - any thoughts on this would be much appreciated. If it is te best way then I need to find a way to avoid validation on all the viewmodels sub models - is this possible?
Thanks in advance for your help.
James
You're right that the user will always enter an amount for both cases, but if I were you I would just avoid the DRY principle so useful when coding but not that much in terms of user interface and go with two independent forms one for each payment type and have an amount field in each one of them.
This way you solve your validation and form submitting problems.
Another option, if you really don't want to have two amount fields on the page I would consider letting the user first choose the payment method and then showing him only the form with the fields for the selected payment method.
Related
I have 8 plans for the user to choose from. These plans all represents forms which would results in products added into the cart.
A few plans will ask different questions. For example plan A,B,C would ask the user if he/she want to purchase additional addon. Plan D,E would ask the user the total credit to store in their account.
This seems to suggest that we have separate views for each of the plan. But this means we then need to add show and edit actions for each of the plan. A bit tedious. So I want to ask if there is a pattern for having record specific view in Rails.
Not really sure if this can be answered in any specific conclusive way, but I would use partials in such a case.
let's assume your plan has a type field somewhere you could do the following
<%= render partial: "plan_#{#plan.type}" %>
Whereas each of these _plan_X.html.erb partials contains the plan specific information you want to display.
This pattern can be adopted for all of your views (maybe your edit action has different data depending on your plan type etc.
I'm building a Rails 3.1 application that allows people to submit events. One of the fields for the event is a venue. On the create/edit form, the venue_name field has autocomplete functionality so it displays venues with a similar name, but the user is able to enter any name.
When the form is submitted, I'm using find_or_create_by_name when attaching the venue to the event model.
I'm doing this because it's not possible for us to maintain a complete list of venues and I don't want to prevent people from submitting an event because the venue isn't in the list.
The problem is that it's quite likely we'll get duplicates over time like "Venue Name" and "The Venue Name" or any number of other possibilities.
I was thinking that I probably just need to create an administrative tool that allows the admin to review recent venues and if he/she thinks they're duplicates to search/select a master record and have the duplicate record's association copied over to the master record and once successful to delete the duplicate record.
Is this a good approach? In terms of the data manipulation would it be best to handle this in a transaction? Would it be best to add this functionality in a sort of utility class - or directly in the Venue model?
Thanks for your time.
If I were going to put together a system like that, I'd probably try to find a unique identifier I could associate with each venue - perhaps an address or a phone number?
So, if I had "The Clubhouse" with a phone number 503-555-1212, and someone tried to input a new venue called "Clubhouse" with the phone number 503-555-1212, I might take them to an interstitial page where I ask them "Did you mean this location?"
Barring that, I might ask for a phone number or address first, then present a list of possible matches with the option to create a new venue.
Otherwise, you're introducing a lot of potential for error at the admin level, plus you run into a scalability problem. If your admin has to review 10 entries a month, maybe not so bad - but if your app takes off and that number goes to 1000, that becomes unmanageable fast!
I am currently using sfDoctrineGuardPlugin and sfDoctrineForkedApplyPlugin for my user management.
This works well for me and users can register/login etc
The problem comes with the registration part. The Profile relation that I have is getting particularly large in terms of fields users are required to fill out on registration.
I was thinking of possibly creating a multistep process, possibly 2 steps.
Step 1 is the main details, such as name, username, password etc
Step 2 is the address and my other fields
I don't want my users to scroll down to fill out 25 fields on a single form
I'm not entirely sure how I'd do this and I cannot find any information regarding carrying out this.
Has anyone ever done this before and If so, could someone point me in the right direction of how I'd do this?
Thanks
I'd create a form class for every step. When processing the submitted form, save the submitted part to the session if validation passes.
In the end you'll have an array of validated values for every step, just compose your model object out of them, and save the object.
Here is a generic way of handling multi-step forms in Symfony:
How to 'validate' a Symfony form in steps - instead of calling $form->isValid()
I have a form where the user can choose options from a lot of select boxes. The form is used to register several items from an RSS feed. The user fills in the form, clicks create and is presented with the same form for the next item in the list.
Sometimes, the same options are valid for several items in the list, and I would like to be able to save some of the selections done so the user doesn't have to make the same selection for the next items.
What is the best way of doing this? I've identified four ways of doing it:
Sessions
Just keep the values in the session hash. This will of course work and is very simple, but I have some undefined feeling that it is a bad idea. It will also not work if the user is using the form from different tabs in the browser.
Cookies
Basically the same as keeping them in the session, I think.
Profile
Can't be done in this case I believe, since profiles are shared between several users.
Database
The most complex way I've come up with is to keep the information in the database and use a query parameter to keep track of which information should be used. This is probably overkill, but in some ways the best way to me. I don't like the idea of keeping this kind of state in session or cookies.
Am I missing some way? Or something?
If after filling first form, some data is saved to db (object is created) then you can use this data from db to fill up new form.
If after filling first form, nothing is saved to db, then you can create in memory some objects based on params from previous post and based on this (on just on params) you can prepare new form. But of course data from previous form should be added as hidden fields in second form.
I haven't even attempted this yet and am creating this question for advice really.
I have a strongly typed page which receives a form model composed of several components. It is to create a mitigating circumstance (MC) for a student at a university for my final year project. A MC can be composed of the initial problem, assessment extensions, and I use a multi select box to allow the user to select staff retrieved from the database which are able to view the MC once created.
The thing is I feel that a student could be granted many assignment extensions for one problem. I am wander if it is possible to include a button/image on the form which when clicked will create a new assessment extension object, and duplicate the form components to set the values for the object? This would all need to occur without any page refreshes.
Any advice, or links to good tutorials would be appreciated. I have so far been unable to find any suitable examples.
Thanks,
Jon
There are a number of ways to do this, but the fastest is to create a javascript handler which creates the form controls without any sort of server request, all you need to do is keep track of how many items are in your list so you can name the form controls correctly.
Start by making a button that when you click on it creates form controls. Once you get that, work on the naming.