Forms. How to make a confirmation action in a text MESSAGE (SMS) form

To enable SMS or Email confirmation in the form, you must do the following: 

1. Add a button to the form

<a href="#" class="as-form-confirm">Confirm</a> 

2. Hide the main save button (it must be on the form!)

.as-form[data-code=client] .as-form-submit{ display: none; }

3. Create a procedure for the request method, where the module is the form code (in this case, client). 

create PROCEDURE [dbo].[request_client_confirm]
	@parameters DictionaryParameter READONLY,
	@username nvarchar(32)
AS
BEGIN
        -- SELECT 1
	select 'All is ок' Msg, 1 Result
	declare @guid uniqueidentifier = newid()

        -- the generated code
	DECLARE @code nvarchar(128);
	declare @count int = 4
	SET @code = (SELECT c1 AS [text()]
		FROM( SELECT TOP (@count) c1 FROM  ( VALUES ('0'), ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'), ('8'), ('9')) AS T1(c1)
		ORDER BY ABS(CHECKSUM(NEWID()))
	) AS T2 FOR XML PATH(''));

        -- SELECT 2 - giving the guid for future verification when saving.
	select @guid [guid]

        -- save the code and Guid for future verification in SaveItem
	insert into as_confirms ([guid], code, date) values (@guid, @code, getdate())

        -- we send the generated code to your email (or SMS)
	select 'email' type,   -- email, sms, notification, clearcache
    'user@mail.ru' [to], 'Confirmation code' subject, 'Validation code - '+@code body

END

4. In SaveItem we check the code

    -- at the entrance to @itemID = @itemID_guid_usercode
    declare @guid nvarchar(256), @code nvarchar(128), @instanceID int
    set @instanceID = try_cast( dbo.str_splitPart(@itemID, '_', 1) as int)

    set @code =  dbo.str_splitPart(@itemID, '_', 2)

    set @guid =  dbo.str_splitPart(@code, '_', 1)
    set @code =  dbo.str_splitPart(@code, '_', 2)

    if( not exists (select id from as_confirms where guid = @guid and code = @code and date > dateadd(minute, -10, getdate()))) begin
    	select 0 Result, 'Wrong code' Msg
        return
    end
    -- ... next comes saving the form

Confirmation window Settings

You can specify settings in the button attributes as-form-confirm

  • data-title-title of the modal window.
  • data-text-description text in the modal window
  • data-placeholder-hint text for the text input field
  • data-btnText-button text in the modal window.
  • data-resendDelay - if specified, the display of the Send again button will be delayed for this number of milliseconds (reinitializing the window + sending sms or mail again). If the attribute is not specified, this button will not be displayed. 
  • data-resendBtnText-text of the Send again button.

Note

  • On the form, we don't use {form-result} to show messages in a popup window.
  • Everywhere in procedures where the @itemID parameter is used, we make it nvarchar(256) - check GetItem, CheckItem, SaveItem, and dict procedures
Falcon Space is a functional web development platform on a narrow stack MS SQL/Bootstrap. Falcon Space Gettting started
{sp-shortDemostandLinks}

Falcon Space Platform

This is a reduction in the cost of ownership

at the expense of fewer people to support

This is a quick change

while using the program

This is a modern interface

full adaptation for mobile devices

Note