Формы обратной связи (xslt)

Материал из Umicms

Перейти к: навигация, поиск

Задача: Выводить на сайте различные формы обратной связи.

Решение: В модуле "Обратная связь" создаем необходимые формы обратной связи. В xsl-шаблоне указываем:

    <xsl:template match="result[page/@id='39']">
	<xsl:apply-templates select="document('udata://webforms/add/127')/udata" mode="forma1"/>
	</xsl:template>
(где 52 - это id страницы, на которой необходимо вывести форму обратной связи, а 127 - id формы обратной связи)

Далее в шаблоне указываем шаблоны для обработки возможных полей формы:

   <xsl:template match="udata[@module = 'webforms'][@method = 'add']">
		<form method="post" action="{$lang-prefix}/webforms/send/" onsubmit="site.forms.data.save(this); return site.forms.data.check(this);" enctype="multipart/form-data">
			<xsl:apply-templates select="items" mode="address" />
			<xsl:apply-templates select="groups/group" mode="webforms" />
			<input type="hidden" name="system_form_id" value="{/udata/@form_id}" />
			<input type="hidden" name="ref_onsuccess" value="/webforms/posted/" />
			<div class="form_element">
				<xsl:apply-templates select="document('udata://system/captcha/')/udata" />
			</div>
			<div class="form_element">
				<input type="submit" class="button" value="Отправить" />
			</div>
		</form>
	</xsl:template>
 
	<xsl:template match="group" mode="webforms">
		<xsl:apply-templates select="field" mode="webforms" />
	</xsl:template>
 
	<xsl:template match="field" mode="webforms">
		<div class="form_element">
			<label>
				<xsl:apply-templates select="." mode="webforms_required" />
				<span><xsl:value-of select="@title" /><xsl:text>:</xsl:text></span>
				<xsl:apply-templates select="." mode="webforms_input_type" />
			</label>
		</div>
	</xsl:template>
 
	<xsl:template match="field" mode="webforms_input_type">
		<input type="text" name="{@input_name}" class="textinputs" />
	</xsl:template>
 
	<xsl:template match="field[@type = 'text']" mode="webforms_input_type">
		<textarea name="{@input_name}"></textarea>
	</xsl:template>
 
	<xsl:template match="field[@type = 'relation']" mode="webforms_input_type">
		<select name="{@input_name}">
			<xsl:if test="@multiple">
				<xsl:attribute name="multiple">
					<xsl:text>multiple</xsl:text>
				</xsl:attribute>
			</xsl:if>
			<option value=""></option>
			<xsl:apply-templates select="values/item" mode="webforms_input_type" />
		</select>
	</xsl:template>
 
	<xsl:template match="field[@type = 'file' or @type = 'img_file' or @type = 'swf_file' or @type = 'video_file']" mode="webforms_input_type">
		<xsl:text> Максимальный размер файла </xsl:text><xsl:value-of select="@maxsize" />Mb
		<input type="file" name="{@input_name}" class="textinputs"/>
	</xsl:template>
 
	<xsl:template match="item" mode="webforms_input_type">
		<option value="{@id}"><xsl:apply-templates /></option>
	</xsl:template>
 
	<xsl:template match="field" mode="webforms_required" />
 
	<xsl:template match="field[@required = 'required']" mode="webforms_required">
		<xsl:attribute name="class">
			<xsl:text>required</xsl:text>
		</xsl:attribute>
	</xsl:template>
 
	<xsl:template match="items" mode="address">
		<xsl:apply-templates select="item" mode="address" />
	</xsl:template>
 
	<xsl:template match="item" mode="address">
		<input type="hidden" name="system_email_to" value="{@id}" />
	</xsl:template>
 
	<xsl:template match="items[count(item) &gt; 1]" mode="address">
		<div class="form_element">
			<label class="required">
				<span><xsl:text>Кому отправить:</xsl:text></span>
				<select name="system_email_to">
					<option value=""></option>
					<xsl:apply-templates select="item" mode="address_select" />
				</select>
			</label>
		</div>
	</xsl:template>
 
	<xsl:template match="item" mode="address_select">
		<option value="{@id}"><xsl:apply-templates /></option>
	</xsl:template>
Личные инструменты