DEV Community

Cover image for WebForms.php Update to WebFormsJS 1.6
Elanat Framework
Elanat Framework

Posted on

WebForms.php Update to WebFormsJS 1.6

In WebForms Core technology, the WebForms class on the server automatically communicates with the WebFormsJS library on the client.
The WebForms class for the PHP programming language is now fully compatible with the latest version of WebFormsJS and takes advantage of all the new features of version 1.6. WebForms Core technology supports all HTML events such as Htmlevent OnMouseDown, OnDrop, OnDrag and others, which is useful for highly dynamic or interactive UIs.

You can download the WebForms class for the PHP programming language from the link below.

https://github.com/elanatframework/Web_forms_classes/blob/elanat_framework/php/WebForms.php

To download the latest version of WebFormsJS, visit the following link.

https://elanat.net/category/download_web_forms_js

In new versions of the WebFormsJS library, you will be able to assign event types to HTML tags.

Example

This script sets background colors for certain HTML elements when users trigger mouse events and includes a framework for managing web forms. When the event isn't set, it dynamically assigns mouse events to change colors.

index.php

<?php
include 'WebForms.php';

$form = new WebForms();

if (isset($_GET['set-color']))
{
    $Color = $_GET['set-color'];
    $Index = $_GET['index'];

    $form->setBackgroundColor('<p>' . $Index, $Color);
    $form->setBackgroundColor('<p>' . $Index, 'unset');
    $form->assignDelay(3);

    echo $form->response();
    exit();
}
?>
<!DOCTYPE html>
<html>
<head>
  <title>Using WebForms Core</title>
  <script type="text/javascript" src="/script/web-forms.js"></script>
</head>
<body>
    <h1>WebForms Core Technology in PHP</h1>
    <p><b>CodeBehind Framework</b> is a modern full-stack framework developed by Elanat in 2023. Built under ASP.NET Core, it competes with Microsoft's default web frameworks like ASP.NET Core MVC, Razor Pages, and Blazor. CodeBehind offers a nostalgic yet innovative approach reminiscent of Microsoft's former WebForms, providing a modular and flexible structure. It supports various development patterns, including MVC, Model-View, Controller-View, and only View, ensuring high server-side independence and simplicity. This framework is known for its speed, simplicity, and adaptability, making it a powerful alternative to ASP.NET Core.</p>
    <p><b>Elanat CMS</b> is a content management system also developed by Elanat, leveraging the CodeBehind Framework. It is designed to be modular and powerful, allowing developers to create and manage various add-ons seamlessly. Elanat CMS supports eight types of add-ons, including components, modules, plugins, pages, patches, and fetch. The CMS is built on a modern architecture that facilitates dynamic add-ons and Ajax postbacks, ensuring a smooth and efficient web development process. With its advanced Ajax capabilities and modular structure, Elanat CMS stands out as a robust solution for managing web content.</p>
    <p><b>WebForms Core technology</b> is a new feature within the CodeBehind framework, providing a modern reinterpretation of Microsoft's former WebForms. Unlike its predecessor, WebForms Core manages HTML tags on the server side, allowing developers to focus on server responses without worrying about the front end. This technology uses a JavaScript library called WebFormsJS to facilitate communication between the server and client. WebForms Core offers a robust infrastructure for web development, ensuring efficient processing and minimal server load. It represents a significant advancement in server-side web development, making it easier for developers to create dynamic and responsive web applications. This technology can be used on all programming languages.</p>

<?php
if (!isset($_GET['set-color']))
{
    $form->setGetEvent('<p>0', HtmlEvent::$onMouseEnter, '?set-color=lightblue&index=0');
    $form->setGetEvent('<p>1', HtmlEvent::$onMouseEnter, '?set-color=lightgreen&index=1');
    $form->setGetEvent('<p>2', HtmlEvent::$onMouseEnter, '?set-color=lightpink&index=2');

    echo $form->exportToWebFormsTag();
}
?>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

The GIF image below shows the mouse enter event on paragraph.
WebForms Core in PHP

Check events

in the upper code of script file, the script starts with including the "WebForms.php" file, which contains the WebForms class.

It creates a new instance of the WebForms class.

Check

include 'WebForms.php';

$form = new WebForms();

if (isset($_GET['set-color']))
{
    $Color = $_GET['set-color'];
    $Index = $_GET['index'];

    $form->setBackgroundColor('<p>' . $Index, $Color);
    $form->setBackgroundColor('<p>' . $Index, 'unset');
    $form->assignDelay(3);

    echo $form->response();
    exit();
}
Enter fullscreen mode Exit fullscreen mode

The script checks if the "set-color" parameter is set in the URL (using $_GET['set-color']).

If the "set-color" parameter is set, it retrieves the color and index values from the URL parameters.

It then sets the background color for a paragraph tag with the specified index using the setBackgroundColor method of the WebForms class.

Then background color set to "unset" and assignDelay method assigns a delay of 3 seconds before executing the this command.

The response generated by the WebForms instance is echoed, and the script exits.

Initialization for set events

Set event

if (!isset($_GET['set-color']))
{
    $form->setGetEvent('<p>0', HtmlEvent::$onMouseEnter, '?set-color=lightblue&index=0');
    $form->setGetEvent('<p>1', HtmlEvent::$onMouseEnter, '?set-color=lightgreen&index=1');
    $form->setGetEvent('<p>2', HtmlEvent::$onMouseEnter, '?set-color=lightpink&index=2');

    echo $form->exportToWebFormsTag();
}
Enter fullscreen mode Exit fullscreen mode

In the final part of the PHP code, it is first checked that the "set-color" value is not present in the query (the state of the initial request of the page from the browser) and then the mouse enter event in the paragraphs in the page is evaluated by setting the query.

Note: Please note that when the HTML page is requested for the first time, if you are using the WebForms class, use the exportToWebFormsTag method. For secondary requests, use the response method.

You can get the sample code in link below.
https://elanat.net/content/27/WebForms.php Updated to WebFormsJS 1.6.html

Top comments (0)