|
| 1 | +## How to work with WebForms Core in C++ (A hypothetical framework) |
| 2 | + |
| 3 | +To use WebForms Core, first copy the WebForms class file in this directory to your project. Then create a new View file similar to the one below. |
| 4 | + |
| 5 | +> Please note that this is a hypothetical framework. The codes below are close to pseudocode, but the WebForms class codes work correctly. |
| 6 | +
|
| 7 | +```c |
| 8 | +#include <iostream> |
| 9 | +#include <string> |
| 10 | + |
| 11 | +#include "backendframework.h" // A hypothetical framework |
| 12 | +#include "WebForms.h" |
| 13 | + |
| 14 | +using namespace std; |
| 15 | + |
| 16 | +int main() { |
| 17 | +// If is post method by submit form |
| 18 | + if (responseForm.hasKey("btn_SetBodyValue")) { |
| 19 | + int fontSize = std::stoi(responseForm.getValue("txt_BackgroundColor")); |
| 20 | + std::string backgroundColor = responseForm.getValue("txt_BackgroundColor"); |
| 21 | + std::string name = responseForm.getValue("txt_Name"); |
| 22 | + |
| 23 | + WebForms form; |
| 24 | + |
| 25 | + form.SetFontSize(InputPlace::Tag("form"), fontSize); |
| 26 | + form.SetBackgroundColor(InputPlace::Tag("form"), backgroundColor); |
| 27 | + form.SetDisabled(InputPlace::Tag("btn_SetBodyValue"), true); |
| 28 | + |
| 29 | + form.AddTag(InputPlace::Tag("form"), "h3"); |
| 30 | + form.SetText(InputPlace::Tag("h3"), "Welcome " + name + "!"); |
| 31 | + form.AssignDelay(78); |
| 32 | + |
| 33 | + std::cout << form.Response() << std::endl; |
| 34 | + return 0; |
| 35 | + } |
| 36 | + |
| 37 | + // If is get method |
| 38 | + std::cout << backEndRender("view")) << std::endl; |
| 39 | + |
| 40 | + return 0; |
| 41 | +} |
| 42 | + |
| 43 | +##End |
| 44 | + |
| 45 | +@@view |
| 46 | +<!DOCTYPE html> |
| 47 | +<html> |
| 48 | +<head> |
| 49 | + <title>Using WebForms Core</title> |
| 50 | + <script type="text/javascript" src="/script/web-forms.js"></script> |
| 51 | +</head> |
| 52 | +<body> |
| 53 | + <form method="post" action="/" > |
| 54 | + |
| 55 | + <label for="txt_Name">Your Name</label> |
| 56 | + <input name="txt_Name" id="txt_Name" type="text" /> |
| 57 | + <br> |
| 58 | + <label for="txt_FontSize">Set Font Size</label> |
| 59 | + <input name="txt_FontSize" id="txt_FontSize" type="number" value="16" min="10" max="36" /> |
| 60 | + <br> |
| 61 | + <label for="txt_BackgroundColor">Set Background Color</label> |
| 62 | + <input name="txt_BackgroundColor" id="txt_BackgroundColor" type="text" /> |
| 63 | + <br> |
| 64 | + <input name="btn_SetBodyValue" type="submit" value="Click to send data" /> |
| 65 | + |
| 66 | + </form> |
| 67 | +</body> |
| 68 | +</html> |
| 69 | +``` |
| 70 | + |
| 71 | +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. |
| 72 | +Please note that if the submit button is not clicked (initial request), the view page will be displayed completely for the requester. |
| 73 | + |
| 74 | +As you can see, the WebFormsJS script has been added in the header section of the View file above. |
| 75 | + |
| 76 | +The latest version of the WebFormsJS script is available through the link below. |
| 77 | + |
| 78 | +https://github.com/elanatframework/Web_forms/blob/elanat_framework/web-forms.js |
0 commit comments