Forum > Networking and Web Programming

fpweb/weblaz questions.

(1/3) > >>

BSaidus:
Hello,
Excuse my ignorance gays and try to be patient with me .
I have some questions about using weblz/fpweb as an alternative to PHP, so I appreciate some help (answers) from you.
   1. Can I use weblz/fpweb as cgi in replacement to PHP ?
   2. Having html, css, js, images (png, jpg) files all ready, Can I deserve them using cgi module ( for lighttpd http server )?

My scenario is, I have my application running in php & I want to convert it in fpc, the application consiste in ONE php(html)file that contain web form and css and js files attached to it, and after each sending data from the form, the php saves that data in json file, and when returning I display that data in the html form again.
In php I just call a function that I made to read the json file into an array then when the browser return after saving, I call this function and I assignes values to edit(s) via.

--- Code: PHP  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  <input class="input-196" type="text" name="ed_qte_tot" placeholder="Quantité totale" value="<?php echo $f_Gcfg["Qte"]["qte_tot"];?>"/> 
so How to integrate that mechanism using fpweb/weblaz ??

Thank you.

   

domasz:
https://wiki.freepascal.org/fpWeb_Tutorial

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Value: String...with AResponse.Contents do beginAdd('<input class="input-196" type="text" name="ed_qte_tot" placeholder="Quantité totale" value="' + Value + '">');
or use some templating system. In PHP there is Smarty. In Smarty you write code like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<input class="input-196" type="text" name="ed_qte_tot" placeholder="Quantité totale" value="{Value}">
Then in Lazarus you can use such files quite easily.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---L: TStringList;Vars: TStringList;  Vars := TStringList.Create;Vars.Add('Var1=Value1');Vars.Add('Var2=Value2');  L := TStringList.Create;L.LoadFromFile('template.htm');for i:=0 to Vars.Count-1 do begin  Name := Vars.Names[i];  Value := Vars.Values[i];     L.Text := StringReplace('{' + Name +'}', Value, [rfReplaceAll]);end; 

BSaidus:
Thanks,
But how about other files ( *.js, *.css, *.png, ... ).
In the handler, I do not think that I should send every file content separatelly  :o :o

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TUfpweb.DataModuleRequest(Sender: TObject; ARequest: TRequest;  AResponse: TResponse; var Handled: Boolean);begin  Handled := true;  AResponse.Contents.LoadFromFile('index.html');end;    
In the scenario of lighttpd, php, I just call

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  /host/index.php and all associated with this resource (index.php) will be downloaded by the briwser.



domasz:
As far as I know fpWeb is a replacement for PHP and lighttpd/Apache/nginx. So you need to reimplement what PHP does and what the www server does.

Leledumbo:

--- Quote from: BSaidus on April 11, 2023, 11:35:03 am ---Can I use weblz/fpweb as cgi in replacement to PHP ?

--- End quote ---
Yes

--- Quote from: BSaidus on April 11, 2023, 11:35:03 am ---Having html, css, js, images (png, jpg) files all ready, Can I deserve them using cgi module ( for lighttpd http server )?

--- End quote ---
Yes, but you shouldn't. Delegate that to a dedicated web server instead. If you insist, see this paragraph from tips and tricks section of my above tutorial.

--- Quote from: BSaidus on April 11, 2023, 11:35:03 am ---How to integrate that mechanism using fpweb/weblaz ??

--- End quote ---
Again, from the same tutorial on different section. I don't really suggest using FPTemplate since it's kinda ancient and not really convenient. FPC has fcl-mustache package documented here (I guess?), this one is better IMO.

Navigation

[0] Message Index

[#] Next page

Go to full version