DEV Community

Cover image for WebForms.php has been Updated to WebForms Core 2
Elanat Framework
Elanat Framework

Posted on • Originally published at elanat.net

WebForms.php has been Updated to WebForms Core 2

The WebForms.php class has been updated from version 1.6 to version 2.0.
This class is now compatible with the WebFormsJS version 2.0 and supports new features of the WebForms Core technology.

The WebForms.php class is built from the WebForms.cs parent class in the C# programming language. The class conversion was done by DeepSeek artificial intelligence and with final monitoring and testing by Elanat.
This WebForms.php version 2.0 class includes the following important changes compared to version 1.6:
Key changes:

  • New data structure: use of simple string and "\n" instead of the NameValueCollection class
  • Performance improvements: add and update methods using strings directly
  • A namespace called WebFormsCore has been added. The usage method is the same as the previous version but with much more features

WebForms Core Technology in PHP


How to use WebForms Core technology?

Two steps are required:
1- On the client side: Add the WebFormsJS script to your HTML page.

<script type="module" src="/script/web-forms.js"></script>
Enter fullscreen mode Exit fullscreen mode

Get the WebFormsJS script from the following link:
https://github.com/webforms-core/Web_forms/blob/elanat_framework/web-forms.js

2- On the server side: Import the WebForms class for your programming language.
Get the WebForms class associated with the server programming language from the following link:
https://github.com/webforms-core/Web_forms_classes

Example:

<?php
include 'WebForms.php';

use WebFormsCore\WebForms;
use WebFormsCore\InputPlace;

if (!empty($_POST['btn_SetBodyValue']))
{
    $Name = $_POST['txt_Name'];
    $BackgroundColor = $_POST['txt_BackgroundColor'];
    $FontSize = (int) $_POST['txt_FontSize'];

    $form = new WebForms();

    $form->setFontSize(InputPlace::tag('form'), $FontSize . 'px');
    $form->setBackgroundColor(InputPlace::tag('form'), $BackgroundColor);
    $form->setDisabled(InputPlace::name('btn_SetBodyValue'), true);

    $form->addTag(InputPlace::tag('form'), 'h3');
    $form->setText(InputPlace::tag('h3'), "Welcome " . $Name . "!");

    echo $form->response();
    exit();
}
?>
<!DOCTYPE html>
<html>
<head>
  <title>Using WebForms Core</title>
  <script type="module" src="/script/web-forms.js"></script>
</head>
<body>
    <form method="post" action="/" >

        <label for="txt_Name">Your Name</label>
        <input name="txt_Name" id="txt_Name" type="text" />
        <br>
        <label for="txt_FontSize">Set Font Size</label>
        <input name="txt_FontSize" id="txt_FontSize" type="number" value="16" min="10" max="36" />
        <br>
        <label for="txt_BackgroundColor">Set Background Color</label>
        <input name="txt_BackgroundColor" id="txt_BackgroundColor" type="text" />
        <br>
        <input name="btn_SetBodyValue" type="submit" value="Click to send data" />

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

In the upper part of the View file, it is first checked whether the submit button has been clicked or not, if it has been clicked, an instance of the WebForms class is created, then the WebForms methods are called, and then the response method is printed on the screen, and other parts Views are not displayed. Please note that if the submit button is not clicked (initial request), the view page will be displayed completely for the requester.


Important note:
Methods that were overloaded in C# (such as SetGetEvent with a different signature) have been renamed to different names in PHP because PHP does not support overloading in the C# way.
Also, a small part of the methods have been renamed due to conflicts with reserved words and standards.
Example:

  • include β†’ includeText
  • break β†’ breakIt
  • goTo β†’ goToLine
  • goTo β†’ goToIndex

All these changes have been made to ensure:

  1. No conflict with PHP keywords
  2. Compliance with PHP naming standards (camelCase)
  3. Avoid ambiguity in method names
  4. Compatibility with PHP language limitations

Why is it necessary to use WebForms Core?

With the growth of interactive web applications and the need for fast and structured communication between the client and the server, using a unified and multilingual core like WebForms Core has become a necessity. WebForms Core is designed to create complete coordination between the front-end layer (WebFormsJS) and the back-end (such as PHP, .NET and other languages), freeing developers from repetitive implementations, scattered logic and complex DOM management. Version 2 of this core, by improving the data structure and increasing performance, enables the development of dynamic, fast and maintainable forms in modern projects.


Advantages of using WebForms Core

  • Focus on the backend: No need for front-end frameworks such as React, Vue and Angular.
  • Full coordination between client and server: A single architecture for managing forms and events without the need for custom JavaScript coding.
  • Multilingual and extensible: Supports multiple server-side languages ​​such as PHP and C# with a common conceptual API.
  • Performance: Using a simple string-based data structure instead of heavy classes results in faster processing.
  • Code complexity: Eliminates the need to send full HTML by directly manipulating the DOM in the backend.
  • Framework compatibility: Easy to use in Laravel, MVC, and other backend architectures.
  • Easier to maintain and develop: Clear separation of UI logic from server-side processing logic.

Top comments (0)