Forms in XMod Pro are defined using HTML and special XMod Pro tags. XMod Pro provides you with the ability to define separate forms to use for adding a record (using the <addform>
tag) and for editing a record using the <editform>
tag. To use third party libraries containing XMod Pro-compatible controls, you use the <register>
tag. This makes the library available to both your add and edit form.
<register .../>
<register .../>
...
<AddForm ClientName="string" ScrollToTop="True|False">
<Variable .../>
...
<SelectCommand.../>
<SubmitCommand.../>
<ControlDataSource .../>
...HTML AND FORM CONTROLS...
</AddForm>
<EditForm ClientName="string">
<Variable .../>
...
<SelectCommand.../>
<SubmitCommand.../>
<ControlDataSource .../>
...HTML AND FORM CONTROLS...
</EditForm>
<AddSuccessTemplate>
<ItemTemplate>HTML, Field Tokens, <xmod:Redirect> tags, and Continue Button/Image/Link controls</ItemTemplate>
</AddSuccessTemplate>
<EditSuccessTemplate>
<ItemTemplate>HTML, Field Tokens, <xmod:Redirect> tags, and Continue Button/Image/Link controls</ItemTemplate>
</EditSuccessTemplate>
Each form definition can contain only one <AddForm>
and one <EditForm>
tag. Though, it is possible to define just the <AddForm>
or <EditForm>
should you only need that form type. All your control tags, HTML tags, and text must fall within the <AddForm>
and <EditForm>
tags. Your HTML and tags should be XHTML compliant for best results.
<AddForm> and <EditForm>
<SelectCommand> and <SubmitCommand>
Form tags rely on "command" tags (<SelectCommand>
, <SubmitCommand>
) to perform their data-related functions. The <SelectCommand>
when specified, is used to populate the form with data when it first loads. The <SubmitCommand>
is executed when the user presses or clicks the Add/Update button in the form. These commands work in
conjunction with the "datafield" and "datatype" attributes of the form control
tags. The datafield attribute values match the parameter names (i.e. @ParamName)
in the commands. The "datatype" attribute enables XMod Pro to pass the control's
value properly to your command. The attributes for these tags are described below:
@name
parameter in the CommandText<ControlDataSource>
Use this optional tag if you want to bind a list-based control to a set of data. More Information
Using [[Field]] Tokens in Your Form
Beginning in version 1.3, XMod Pro now supports the ability to use data from your <SelectCommand> in the attributes of your form controls. This allows you to retrieve values from your database or from passed-in parameters or hard-coded values in your forms to further enhance their dynamic nature. For instance, if a customer is ordering a product, your <SelectCommand> can look that product up in the inventory database and set the MaximumValue of the Range Validator so that it prevents the user from ordering more a quantity greater than the stock you have in the warehouse.
Using [[Field]] tokens is easy. They follow the same rules as [[Field]] tokens in templates. Example:
<AddForm>
<SelectCommand CommandText="SELECT StockOnHand FROM Inventory
WHERE ProductId = @ProductId">
<Parameter Name="ProductId" Value='[[Url:pid]]' DataType="Int32" />
</SelectCommand>
...
<TextBox Id="txtQuantity" DataField="Qty" DataType="Int32"/>
<Validate type="Range" target="txtQuantity" minimumvalue="1"
maximumvalue='[[StockOnHand]]'
message='[[Join("You can only order between 1 and {0} tickets",[[StockOnHand]])]]'
type="Integer"/>
<AddSuccessTemplate>, <EditSuccessTemplate>
These tags are optional. They provide you with the ability to display a "thank you" or a "completed" type of message to your user after successful submission of the form. The AddSuccessTemplate tag is used when the AddForm is submitted. The EditSuccessTemplate tag is used when the EditForm is submitted. When displayed, the content of the tag's <ItemTemplate>
tag will be displayed in place of the Add/Edit form.
Enabling Your Users to Continue After Successful Form Submission:The AddSuccessTemplate and EditSuccesTemplates tags accept <xmod:ContinueButton>
, <xmod:ContinueImage>
, and <xmod:ContinueLink>
controls. These render as a button, image, or link, respectively. They act as "OK" buttons. When clicked, these buttons will take the user to the page/view they would ordinarily see after submitting their form without the success message. Of course, you can also send the user to the URL of your choice. Each of these buttons has a Redirect attribute that takes a destination URL. When used, the user will be redirected to that URL. NOTE: if you want to POST values to a destination URL, you should use the <xmod:Redirect>
tag.
You can use text, HTML, and [[Field]]
tokens to craft your success message. Note that the [[Field]]
tokens will be replaced at run-time by the values in the form's data-bound fields, rather than values actually saved to the database.
Displaying the return value and/or Output parameter value from a stored procedure (new to v.4): If your form's SubmitCommand calls a stored procedure that returns a value or sets the value of an output parameter, you can display or otherwise use that value in your success template
IMPORTANT: When calling stored procedures in your SubmitCommand, you MUST declare all the parameters you're passing to the stored procedure. Because you can have controls on your form that you may not pass to the database (i.e. using an entered value in an Email or Redirect) XMod Pro cannot automatically generate those stored procedure parameters for you.
<SubmitCommand CommandText="addContact" CommandType="StoredProcedure">
<SubmitCommand CommandText="addContact" CommandType="StoredProcedure">
<Parameter Name="FirstName" />
<Parameter Name="LastName" />
</SubmitCommand>
<SubmitCommand CommandText="addContact" CommandType="StoredProcedure">
<Parameter Name="FirstName" />
<Parameter Name="LastName" />
<Parameter Name="retVal" Direction="ReturnValue" />
<Parameter Name="newID" Direction="Output" DataType="int32" />
</SubmitCommand>
<SubmitCommand CommandText="addContact" CommandType="StoredProcedure">
<Parameter Name="FirstName" />
<Parameter Name="LastName" />
<Parameter Name="retVal" Direction="ReturnValue" />
<Parameter Name="newID" Direction="Output" DataType="int32" />
<Parameter Name="ERROR" Direction="Output" DataType="string" />
</SubmitCommand>
...
<AddButton Text="Add" />
<Validate Type="Database" />
<ValidationSummary />
<AddSuccessTemplate>
This is my return value: [[retVal]] <br />
<xmod:Redirect Display="Button" Text="View New Record" Target="href://mysite.com/TeamDetail.aspx" Method="Post">
<Field Name="teamid" Value='[[newID]]' />
</xmod:Redirect>
</AddSuccessTemplate>
<Variable>
Variable tags, new to version 2.7, are optional tags you can use to provide additional data to your form. Variables are not rendered to the form but are available to your data commands and controls. For instance, you might use a variable to store the portal's ID. Then, in your SubmitCommand, you can use that variable to store the Portal ID in the record along with other form values. Another possibility would be to use the <Text> tag to display information to the user from Variables or, perhaps, to configure a Javascript function in your form.
Syntax: <Variable Name="uniqueName" Value="variableValue" DataType="string|Int32|Int64|boolean|..."/>
The name you provide the variable is used just like column names are used with your data commands. You can bind controls to the variable by specifying the variable's Name as the control's DataField property. The Value can be a hard-coded value or one of XMod Pro's tokens - like [[Portal:ID]]. When using a token, ensure that the Value is delimited with single-quotes rather than double quotes. Finally, the DataType property allows you to specify the type of value the variable contains. The default data type is String.
Variable tags are typically placed at the top of each form. Sample:
<AddForm>
<Variable Name="thePortalId" Value='[[Portal:ID]]' DataType="Int32" /> <SubmitCommand CommandText="INSERT INTO MyTable (Name,PortalId) VALUES(@Name,@thePortalId)" /> ... <TextBox id="txtName" DataField="Name" DataType="String" /> ... </AddForm>
Back to top
<addform>
<selectcommand commandtext="SELECT @FirstName AS FirstName, @LastName AS LastName,
'AZ' AS StateId">
<parameter name="FirstName" value='[[User:FirstName]]' defaultvalue=""/>
<parameter name="LastName" value='[[User:LastName]]' defaultvalue="" />
</selectcommand>
<submitcommand commandtext="INSERT INTO Users(FirstName,
LastName, StateId)
VALUES(@FirstName, @LastName, @StateId)" />
<controldatasource id="dsStates" connectionstring="(your connection string here)"
commandtext="SELECT StateName, StateId FROM States ORDER BY StateName ASC" />
<table>
<tr>
<td>
<label for="txtFirstName" text="First Name" />
<textbox id="txtFirstName" datafield="FirstName"
datatype="string" />
</td>
</tr>
<tr>
<td>
<label for="txtLastName" text="Last Name" />
<textbox id="txtLastName" datafield="LastName"
datatype="string" />
</td>
</tr>
<tr>
<td>
<label for="ddlState" text="State" />
<dropdownlist id="ddlState" datafield="StateId"
datatype="int32"
datasourceid="dsStates" datatextfield="StateName" datavaluefield="StateId"/>
</td>
</tr>
<tr>
<td colspan="2">
<addbutton text="Add"/> <cancelbutton
text="Cancel"/>
</td>
</tr>
</table>
<email to="
me@mysite.com
" from="server@mysite.com"
subject="New User Added"
format="html">
<content>
A new user has been added:<br />
FirstName: [[FirstName]]<br />
LastName: [[LastName]]
</content>
</email>
</addform>
<editform>
<selectcommand commandtext="SELECT * FROM Users WHERE UserId =
@UserId AND PortalId = @PID">
<parameter name="PID" value='[[Portal:ID]]'/>
</selectcommand>
<submitcommand commandtext="UPDATE Users SET
FirstName=@FirstName,
LastName=@LastName,
StateId=@StateId
WHERE UserId=@UserId" />
<controldatasource id="dsStates" connectionstring="(your connection string here)"
commandtext="SELECT StateName, StateId FROM States ORDER BY StateName ASC" />
<table>
<tr>
<td>
<label for="txtFirstName" text="FirstName" />
<textbox id="txtFirstName" datafield="FirstName"
datatype="string" />
</td>
</tr>
<tr>
<td>
<label for="txtLastName" text="Last Name" />
<textbox id="txtLastName" datafield="LastName"
datatype="string" />
</td>
</tr>
<tr>
<td>
<label target="ddlState" text="State" />
<dropdownlist id="ddlState" datafield="StateId"
datatype="int32"
datasourceid="dsStates" datatextfield="StateName" datavaluefield="StateId"/>
</td>
</tr>
<tr>
<td colspan="2">
<updatebutton text="Update"/> <cancelbutton
text="Cancel"/>
</td>
</tr>
</table>
<textbox id="txtUserId" datafield="UserId"
datatype="int32" visible="false" />
</editform>
<AddSuccessTemplate>
<ItemTemplate>
<h1>Form Submission Successful</h1>
<p>Thanks for your submission, [[FirstName]]. We'll email you once
we've completed the review process</p>
<xmod:ContinueButton Text="Continue" />
</ItemTemplate>
</AddSuccessTemplate>
<EditSuccessTemplate>
<ItemTemplate>
<h1>Record Update Successful</h1>
<p>Thanks for updating your submission, [[FirstName]]. We'll email you once
we've completed the review process</p>
<xmod:ContinueButton Text="Continue" />
</ItemTemplate>
</EditSuccessTemplate>