I have an online form that collects the user's contact information. Typical stuff - first & last name, address, city, state, zip, etc.
At one point in the process, they can enter information for another person as well. At that point, I show a modal popup with the very same fields for this other person.
I hate the repetition of the fields in my ASCX file. I'd like to define a single block of fields and show them in different contexts.
A twist to the plot is that the admin of the site can configure which fields are visible for each of the two contexts.
For example, they might say for the primary user, we want to ask for phone number, but we don't want to show that field for the additional people. In that situation, the phone number field would be visible for the main form, but hidden in the modal popup.
So the question is: What is the best way to reuse the same fields in different places of an ASP.NET form?
You can add another flag to your user control
Note : this flag must be declared as public property
public bool Flag
{
get;
set;
}
Your User control
First instance : <UCTagPrefix:UCTagName runat="server" id="" Flag="true"/>
Second instance : <UCTagPrefix:UCTagName runat="server" id="" Flag="false"/>
you can use another type if you want, this sample is based on boolean
Adapt the behavior of your user control with the value of your flag , in your code behind
If admin wants to configure visibility of each field, I think it would be better to add the field list to a database table like fieldName, userType1 (bit), userType2 (bit),... and then add the value 0 or 1 (Admin could do this via interface).
When you load the control get the corresponding values by passing userType to the database (stored procedure or query) and set visibility of each field accordingly.
Related
I am trying to make form builder in android. I have a real problem at designing database. In this application User first drags the required fields to the screen and change the labels of fields. The fields Contains:
CheckBox
RadioButton
TeXtBox
PlainText
This is my mockup:
I have real problem in designing database.I need a help to accomplish it.
Any Links to the tutorials or ER Diagrams will be really appreciated.
In this application user will drag his required fields to the screen as shown in mock up. Suppose when user drags on checkbox icon then the Editable Checkbox label and editable options will appear in the screen. Then Form builder names the label according to his requirements and options also. In this way he first builds the form .
That's what I created in 10 minutes, hope it helps.
TB_FieldType //field type
UUID_Type,
Type_Name, (Checkbox, RadioButton, Textbox, PlainText, Password, DropdownSelect...)
TB_FieldRule //Table field rule
UUID_Rule,
Rule (numeric only, not null...)
TB_UserTable //Save user designed thrir own table
UUID_Table,
Table_Name, (Designed table name)
TB_UserTable_Field //Designed table field detail
UUID_TableField,
UUID_Table,
UUID_Type,
UUID_GroupID, (can be null if field is single type*)
UUID_Rule,
Field_Name, (Display name)
Field_Length,
TB_Group //(for field(s) in multi type*, like RadioButton, DropwodnSelect... )
UUID,
GroupID,
GroupData,
I would create a table for storing the field definitions with fields like this:
survey_id (reference to the survey which the field belongs to)
field_id (unique id of the field)
field_type (checkbox, radio, plain etc.)
field_label
field_data (additional information if required, e.g. selection options for radio - dependent on type)
field_index (defines the order of fields)
... any additional field you may need
From this data, you can dynamically build your GUI.
And you will need another table for storing the answers (if it is in scope of your app):
field_id (reference to the former table)
value (entered by the user)
...user_id, timestamp etc. according to your needs
I'm writing a simple content type with Dexterity to manage customers, beside the usuals fields, eg name, company, phone...
I've also added a Datetime field to store when the first meeting with
customers has been held, lets call it 'firstmeeting', which I defined
in my interface ICustomers as:
firstmeeting = schema.Datetime(
title=_(u"First Meeting"),
required=False,
)
Now, I notice that when I saved a new Customer document the firstmeeting
field has been filled with the current date even if I don't set any date
in the form, which is not what I want because no meeting with the
customer has been held yet. So I'd like to know how to set a None value
for this field so nothing will be displayed.
I've been trying to use a custom class has explained by Martin Aspeli in
http://plone.org/products/dexterity/documentation/manual/developer-manual/advanced/classes
but I don't know how to check the user input and set None value if nothing
was typed in.
Thanks
Have you tried default=None?
I found out what was happening in my code.
Actually the problem was in the template view.pt where I used toLocalizedTime() function,
which was converting the None value to the current date, so I added a tal:condition to print the date value.
<span id="form-widgets-firstmeeting" class="datetime-widget datetime-field"
tal:condition="context/firstmeeting"
tal:content="python:context.toLocalizedTime(context.firstmeeting)" />
I have to design a page for user information, for some background verification purpose, at my work. I need a set of fields for address, total count of which will be selected by user to update the form with that many fields. So, if user selects 3, form will have 3 set of address fields. Similar concept for work and education details.
Right now, I am passing the count to a handler page, which checks total count, and return it along with querystring, back to the main page. I am able to update the no. of fields, this way, but, all values are lost, once I return to the form. There are a lot of fields to even use session object for every value. Also, it resets the count of other such field set to 0. So, if I select 4 in address field, it renders four set of address fields, but fields for other details are gone.
I need to know, if it is possible to update the fields, using just one page, instead of creating a handler file to handle the redirect, so that I don't lose other data.
Sorry, for sounding a bit confusing. Will update the question, if needed.
Edit:
Similar blocks are there for education and work details. I want the update button to update the block, with that many fields, while retaining the values already entered by the user.
I have finally shifted the update code to one page. And the total count of blocks, is calculated by this way.
if request.form("addresscount") <> "" then
varaddresscount = request.form("addresscount")
else
varaddresscount = 1
end if
varaddresscount is used to loop through the html code which renders address fields. Even with this method, if I click on update button to change the total field count, every value entered by user is reset to default. Is there a way to retain the no. of fields without using session object, as there are way too many fields for which I have to store the value in session.
Why not have just a "add address" button that, whenever clicked, adds a extra set of input boxes using Javascript? That solves a lot of your problems regarding retaining the data on already filled in fields AND it makes it easier for the user.
I am working on a form which displays information about orders. Each order has a unique id, but they are not necessarily sequential on the form. Also, the number of fields can vary (one field per row on the form). The input into the form will not be mapped straight into the database, but will be added to the current value in the database, and then saved. An example of the form is in the picture below - the callout on the right shows the id for each row.
I know how to generate the form like this, but I can't work out how I can easily process each of these rows reliably. I also know how to give each of the fields a unique identifier, like name="order-23" or name="order[23]", but how can I translate that name so that I can update the related record in the database?
EDIT: One solution I can think of would be to iterate through every form field in the FormCollection, and if the name of the field matches the pattern, then I will extract the number from that field-name and process it.
However, I feel that there must be a much easier way to go about it - this method would likely involve a fair bit of string processing on each field, and there would possibly fall over if I have to add extra fields for each row later on.
Don't you have a list of IDs after postback? I believe you should not depend on what IDs are actually sent from the form, as anybody could change the IDs on the form to whatever they want, so it's a security issue. So you should after postback have a list of IDs you want to update (the same list you used to create the form with). In that case, you know exactly what id string you should use to retrieve the value from FormCollection.
In case you really can't get the list of IDs you are going to update, just use the FormCollection iteration as you suggested in your comment. The string processing is not that expensive in comparation with all other stuff being done at request processing.
If you have the names, then simply read the values by using Request.Form["order-23"] or re-create the controls in page pre-init and you'll have access to the values in your save event directly through the created controls.
I've done this loads in my CMS.
Essentially i sort of cheated.
The idea is something like this ....
render the form to the client, then look at the source code gneerated.
You should see that it generated a form tag with an action attribute.
When you click the submit button the form will be sent to that url so in the case of an order submission you would post the page back to OrderPage.aspx?OrderId=xxxx
then on the server you would build an update statement for your db that contained something like ...
"Update orders where order id =" + request.querystring["OrderId"]
So how do you update the action ...
In the calling page lets say you have a link called "New Order", when that link is clicked you need to do 2 things ...
redirect to this page.
generate an order id for this new order.
ok the first is simple, simply link it to this page.
the second ...
if this page is not a postback if(!IsPostback) { /* get a new id */ } depending on your order id's this may involve generating a new guid or doing something like getting the next number in a list by doing a select max(id) from a db.
once you have this new id you should still be in the page_load event.
this.form.Action = this.form.Action + "?OrderId=" + yourNewOrderId;
... tada ...
Send page back to the client.
view the source.
Does anyone know how to retrieve and display data from database using combo list? What I mean is this..I have a form..in the form there is a combo list and two textfiels..the user need to choose their company using that combo list..once they have chose their company, the address and contact number of the company will be display in the next two textfields called CAddress and CContact..for example, if the user chose company ABC..how can I display the company ABC address and contact number in those textfields? Need help. Thanks.
first of all you could use javascript and make a call ajax to an asp page passing the id of the company ... in that page you can jsut response.write the infos u need as a xml format ... even csv format would work ... then jsut take the response and write it in the textbox