Adding a New Field
By Paul
3.36/5 based on 11 votes. The median rating is 4.
By Paul
Sometimes, you want to collect more data from the user than the WSN normally asks for. You might want to ask for a contact name, a color, or so forth depending on what type of item you're dealing with.
Go to Admin Panel -> Customizations -> Add Fields. For example purposes, suppose you want listing submitters to be able to specify a color for the listing they're submitting. Choose 'listing field' and type a suitable name such as 'color' (please note that the field name has to be alphanumeric, no spaces or accented characters -- keep it short and simple).
Next, select the desired way to collect the input from the user -- a simple input box, a dropdown selector, checkboxes or the like. The simplest method is a regular input box, that's what you usually want. If the content will be a large amount of text (perhaps an article), you will want to choose the 'text area' option. If you wish to display options to let the submitter check a box for each one that applies to their listing, use checkboxes. If you want to let them choose a single option from a dropdown menu (like the category selector in the top right of your screen now), then choose 'dropdown selector'. If you want a combo box that allows multiple selections (like your 'related categories' options on the edit category page), choose 'multiselect combo box'. To list several options in the same style as checkboxes but only allow the submitter to choose exactly one option (no more, no less), choose 'radio button'. If this field is not something that you want to be selectable or editable by anyone (even yourself), you may wish to make it invisible.
The following step is to choose the display name, which is what the visitor is prompted for (instead of the field name, which is for internal purposes only). For example, for a field named productsize you could use the label "Product Size".
Now you can select if non-administrators will be able to fill in the field. If you check the first box, it will appear to everyone as an option on the submit listing page. If you check the second box, it will appear on the edit listing page for all listing owners to edit (presuming you've set usergroup permissions to let them edit their listings).
Finally, if you chose an input option which involves multiple choices you can write out the options separated by commas. For most input types this is not applicable, it's just for checkboxes and selectors and radio buttons.
Once you're ready and have double checked everything, press 'Add Field' to create your field.
You can customize the exact HTML you're using to collect the data in the "Custom Fields" templates section -- Admin Panel -> Templates -> Manage Templates -> "Custom Fields". The submit and edit templates automatically call these custom field templates with an [INSERTFILE=] call. To rearrange positions more freely, you can cut and paste out the custom fields templates into the submit and edit templates at your desired location.
Displaying Data
You're collecting the data. Now, you want to display it. Where you display it depends on what type of field you've added. Most of the time you'll probably be adding listing fields, so we'll discuss that first.
The most common place you'll want to display listing information is the listing details page. Go to Admin Panel -> Templates -> Manage Templates -> "Listing Details". Data for new listing fields is automatically displayed at the location of the <!-- INSERT NEW FIELDS HERE --> maker in the listing details template -- so you can just customize what it inserts for you. The template variable to use to display the content of any listing field is {LINK + FIELDNAME + }. If your listing field is named color, {LINKCOLOR} is your template variable to display it. Type this into a template at the location you want it displayed, with the label you want. For example, write "<p>Listing Color: {LINKCOLOR}</p>" to make a paragraph displaying the color. If you only want to display the line when there's a color value filled in, conditionalize it to <IF {LINKCOLORBOOL}></p>Listing Color: {LINKCOLOR}</p></IF>. The most common places you'll want to display it are the details template and in the type manager's display code for each listing type (Admin Panel -> Settings -> Type Manager).
For other types of fields, find the associated display template at Admin Panel -> Templates -> Manage Templates and use the template variable (of the form { + TYPEPREFIX + FIELDNAME + }) that's given to you at the time you add the field. For a category field, you'll probably want to show it in the main index template. For a member field, the member profile. If the field is named color, the template variables would be {CATCOLOR} and {MEMBERCOLOR} respectively.
Selectors and Checkboxes Notes
If you're dealing with a single checkbox or single selector and want to test if a value is selected, you can use {LINKCHECKED[fieldname]} (or {CAT, {MEMBER etc) in your template conditional.
If dealing with multi-value checkboxes or selectors, you can use <IF {LINKCHECKED[fieldname <,> value]}>has specified value</IF> to test for each value. If you just want a comma-separated list of all selected values, use {LINKSELECTIONSLIST[fieldname]}. Don't use the plain {LINKFIELDNAME} template variable as it will not produce the expected results for a mutli-value field.
Searching Custom Fields
You can easily extend the advanced search option to allow visitors to search in your new custom field. Go to Admin Panel -> Templates -> Manage Templates -> "Advanced Search" and just copy the code for one of the other fields and change the field names to your new field. For example (this example is for a multilingual installation, english-only will look different), find
Go to Admin Panel -> Customizations -> Add Fields. For example purposes, suppose you want listing submitters to be able to specify a color for the listing they're submitting. Choose 'listing field' and type a suitable name such as 'color' (please note that the field name has to be alphanumeric, no spaces or accented characters -- keep it short and simple).
Next, select the desired way to collect the input from the user -- a simple input box, a dropdown selector, checkboxes or the like. The simplest method is a regular input box, that's what you usually want. If the content will be a large amount of text (perhaps an article), you will want to choose the 'text area' option. If you wish to display options to let the submitter check a box for each one that applies to their listing, use checkboxes. If you want to let them choose a single option from a dropdown menu (like the category selector in the top right of your screen now), then choose 'dropdown selector'. If you want a combo box that allows multiple selections (like your 'related categories' options on the edit category page), choose 'multiselect combo box'. To list several options in the same style as checkboxes but only allow the submitter to choose exactly one option (no more, no less), choose 'radio button'. If this field is not something that you want to be selectable or editable by anyone (even yourself), you may wish to make it invisible.
The following step is to choose the display name, which is what the visitor is prompted for (instead of the field name, which is for internal purposes only). For example, for a field named productsize you could use the label "Product Size".
Now you can select if non-administrators will be able to fill in the field. If you check the first box, it will appear to everyone as an option on the submit listing page. If you check the second box, it will appear on the edit listing page for all listing owners to edit (presuming you've set usergroup permissions to let them edit their listings).
Finally, if you chose an input option which involves multiple choices you can write out the options separated by commas. For most input types this is not applicable, it's just for checkboxes and selectors and radio buttons.
Once you're ready and have double checked everything, press 'Add Field' to create your field.
You can customize the exact HTML you're using to collect the data in the "Custom Fields" templates section -- Admin Panel -> Templates -> Manage Templates -> "Custom Fields". The submit and edit templates automatically call these custom field templates with an [INSERTFILE=] call. To rearrange positions more freely, you can cut and paste out the custom fields templates into the submit and edit templates at your desired location.
Displaying Data
You're collecting the data. Now, you want to display it. Where you display it depends on what type of field you've added. Most of the time you'll probably be adding listing fields, so we'll discuss that first.
The most common place you'll want to display listing information is the listing details page. Go to Admin Panel -> Templates -> Manage Templates -> "Listing Details". Data for new listing fields is automatically displayed at the location of the <!-- INSERT NEW FIELDS HERE --> maker in the listing details template -- so you can just customize what it inserts for you. The template variable to use to display the content of any listing field is {LINK + FIELDNAME + }. If your listing field is named color, {LINKCOLOR} is your template variable to display it. Type this into a template at the location you want it displayed, with the label you want. For example, write "<p>Listing Color: {LINKCOLOR}</p>" to make a paragraph displaying the color. If you only want to display the line when there's a color value filled in, conditionalize it to <IF {LINKCOLORBOOL}></p>Listing Color: {LINKCOLOR}</p></IF>. The most common places you'll want to display it are the details template and in the type manager's display code for each listing type (Admin Panel -> Settings -> Type Manager).
For other types of fields, find the associated display template at Admin Panel -> Templates -> Manage Templates and use the template variable (of the form { + TYPEPREFIX + FIELDNAME + }) that's given to you at the time you add the field. For a category field, you'll probably want to show it in the main index template. For a member field, the member profile. If the field is named color, the template variables would be {CATCOLOR} and {MEMBERCOLOR} respectively.
Selectors and Checkboxes Notes
If you're dealing with a single checkbox or single selector and want to test if a value is selected, you can use {LINKCHECKED[fieldname]} (or {CAT, {MEMBER etc) in your template conditional.
If dealing with multi-value checkboxes or selectors, you can use <IF {LINKCHECKED[fieldname <,> value]}>has specified value</IF> to test for each value. If you just want a comma-separated list of all selected values, use {LINKSELECTIONSLIST[fieldname]}. Don't use the plain {LINKFIELDNAME} template variable as it will not produce the expected results for a mutli-value field.
Searching Custom Fields
You can easily extend the advanced search option to allow visitors to search in your new custom field. Go to Admin Panel -> Templates -> Manage Templates -> "Advanced Search" and just copy the code for one of the other fields and change the field names to your new field. For example (this example is for a multilingual installation, english-only will look different), find
<br />{LANG_SEARCH_THETITLE}
<select name="titlecondition">
<option value="like">{LANG_SEARCH_CONTAINS}</option>
<option value="=">{LANG_SEARCH_EQUALS}</option>
<option value="or">{LANG_SEARCH_CONTAINSANY}</option>
<option value="and">{LANG_SEARCH_CONTAINSALL}</option>
<option value="!=">{LANG_SEARCH_NOTEQUALS}</option>
<option value="bool">{LANG_SEARCH_BOOL}</option>
</select>
<input type="text" size="{STANDARDSIZE}" name="titlesearch" />
and add this below it: <select name="titlecondition">
<option value="like">{LANG_SEARCH_CONTAINS}</option>
<option value="=">{LANG_SEARCH_EQUALS}</option>
<option value="or">{LANG_SEARCH_CONTAINSANY}</option>
<option value="and">{LANG_SEARCH_CONTAINSALL}</option>
<option value="!=">{LANG_SEARCH_NOTEQUALS}</option>
<option value="bool">{LANG_SEARCH_BOOL}</option>
</select>
<input type="text" size="{STANDARDSIZE}" name="titlesearch" />
<br />and fieldname
<select name="fieldnamecondition">
<option value="like">{LANG_SEARCH_CONTAINS}</option>
<option value="=">{LANG_SEARCH_EQUALS}</option>
<option value="or">{LANG_SEARCH_CONTAINSANY}</option>
<option value="and">{LANG_SEARCH_CONTAINSALL}</option>
<option value="!=">{LANG_SEARCH_NOTEQUALS}</option>
<option value="bool">{LANG_SEARCH_BOOL}</option>
</select>
<input type="text" size="{STANDARDSIZE}" name="fieldnamesearch" />
replacing fieldname with your actual custom field name.
<select name="fieldnamecondition">
<option value="like">{LANG_SEARCH_CONTAINS}</option>
<option value="=">{LANG_SEARCH_EQUALS}</option>
<option value="or">{LANG_SEARCH_CONTAINSANY}</option>
<option value="and">{LANG_SEARCH_CONTAINSALL}</option>
<option value="!=">{LANG_SEARCH_NOTEQUALS}</option>
<option value="bool">{LANG_SEARCH_BOOL}</option>
</select>
<input type="text" size="{STANDARDSIZE}" name="fieldnamesearch" />
Rating:
3.36/5 based on 11 votes. The median rating is 4.
Submitted: 11/10/03 (Edited 06/09/11)
Description: Tracking new data.
Views:
3978 views. Averaging 1 views per day.
In the most recent 30 day period, there've been 19 views.

Print
E-Mail