Recent

Author Topic: fpweb/weblaz questions.  (Read 968 times)

BSaidus

  • Sr. Member
  • ****
  • Posts: 495
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
fpweb/weblaz questions.
« on: April 11, 2023, 11:35:03 am »
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  [Select][+][-]
  1.   <input class="input-196" type="text" name="ed_qte_tot" placeholder="Quantité totale" value="<?php echo $f_Gcfg["Qte"]["qte_tot"];?>"/>
  2.  

so How to integrate that mechanism using fpweb/weblaz ??

Thank you.

   
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

domasz

  • Sr. Member
  • ****
  • Posts: 320
Re: fpweb/weblaz questions.
« Reply #1 on: April 11, 2023, 12:12:22 pm »
https://wiki.freepascal.org/fpWeb_Tutorial
Code: Pascal  [Select][+][-]
  1. Value: String
  2. ...
  3. with AResponse.Contents do begin
  4. Add('<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  [Select][+][-]
  1. <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  [Select][+][-]
  1. L: TStringList;
  2. Vars: TStringList;
  3.  
  4.  
  5. Vars := TStringList.Create;
  6. Vars.Add('Var1=Value1');
  7. Vars.Add('Var2=Value2');
  8.  
  9.  
  10. L := TStringList.Create;
  11. L.LoadFromFile('template.htm');
  12. for i:=0 to Vars.Count-1 do begin
  13.   Name := Vars.Names[i];
  14.   Value := Vars.Values[i];  
  15.  
  16.   L.Text := StringReplace('{' + Name +'}', Value, [rfReplaceAll]);
  17. end;
  18.  
« Last Edit: April 11, 2023, 12:18:25 pm by domasz »

BSaidus

  • Sr. Member
  • ****
  • Posts: 495
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: fpweb/weblaz questions.
« Reply #2 on: April 11, 2023, 01:07:30 pm »
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  [Select][+][-]
  1. procedure TUfpweb.DataModuleRequest(Sender: TObject; ARequest: TRequest;
  2.   AResponse: TResponse; var Handled: Boolean);
  3. begin
  4.   Handled := true;
  5.   AResponse.Contents.LoadFromFile('index.html');
  6. end;  
  7.  

In the scenario of lighttpd, php, I just call
Code: Pascal  [Select][+][-]
  1.   /host/index.php
  2.  
and all associated with this resource (index.php) will be downloaded by the briwser.



lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

domasz

  • Sr. Member
  • ****
  • Posts: 320
Re: fpweb/weblaz questions.
« Reply #3 on: April 11, 2023, 01:38:31 pm »
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.
« Last Edit: April 11, 2023, 01:45:22 pm by domasz »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8717
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: fpweb/weblaz questions.
« Reply #4 on: April 11, 2023, 02:28:33 pm »
Can I use weblz/fpweb as cgi in replacement to PHP ?
Yes
Having html, css, js, images (png, jpg) files all ready, Can I deserve them using cgi module ( for lighttpd http server )?
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.
How to integrate that mechanism using fpweb/weblaz ??
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.

BSaidus

  • Sr. Member
  • ****
  • Posts: 495
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: fpweb/weblaz questions.
« Reply #5 on: April 11, 2023, 08:25:32 pm »
Thank you for help & information.
I'll try and see.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

BSaidus

  • Sr. Member
  • ****
  • Posts: 495
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: fpweb/weblaz questions.
« Reply #6 on: April 14, 2023, 09:42:31 am »
I constat that fcl-mustache do not come for fpc3.2.2
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Leledumbo

  • Hero Member
  • *****
  • Posts: 8717
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: fpweb/weblaz questions.
« Reply #7 on: April 14, 2023, 12:21:43 pm »
I constat that fcl-mustache do not come for fpc3.2.2
Yes, it's a little bit too late. 3.2.2 was released on May 2021, which already has feature frozen a couple of months before. The first commit to fcl-mustache happend in April 2021. However, the package itself compiles fine with 3.2.2, so if you have to stick with it, you can just grab the folder or even just the unit (only fpmustache.pas matters, unless you need the expression parser / dataset extension).

BSaidus

  • Sr. Member
  • ****
  • Posts: 495
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: fpweb/weblaz questions.
« Reply #8 on: April 14, 2023, 06:37:22 pm »
thanks @Leledumbo
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

BSaidus

  • Sr. Member
  • ****
  • Posts: 495
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: fpweb/weblaz questions.
« Reply #9 on: April 14, 2023, 10:51:14 pm »
Please help.
Given this json data
Code: Javascript  [Select][+][-]
  1. {
  2.   "host":{
  3.     "name"     : "uc1.uccenos.net",
  4.     "ip"       : "123.33.32.1",
  5.     "mask"     : "222.222.222.0",
  6.     "gateway"  : "123.33.23.3"
  7.   }
  8. }
  9.  
  10.  
and this template with expression
Code: Text  [Select][+][-]
  1. <br/>
  2. <ul>
  3.   <li>hostnam : {{host.name}}   </li>
  4.   <li>ip      : {{host.ip}}     </li>
  5.   <li>mask    : {{host.mask}}   </li>
  6.   <li>gateway : {{host.gateway}}</li>
  7.  <select name="themask">
  8. '
  9.     <option value="111.222.333.111" {{[IF((comparetext(mask,'111.222.333.111')=0), 'selected','')]}}> 111.222.333.111 </option>
  10.     <option value="222.222.222.0"     {{[IF((comparetext(mask,    '222.222.222.0')=0), 'selected','')]}}> 222.222.222.0   </option>  
  11.     <option value="333.222.333.111" {{[IF((comparetext(mask,'333.222.333.111')=0), 'selected','')]}}> 333.222.333.111 </option>
  12.  
  13. </select>
  14.  

I have tried all combinaisons but do not work
Code: Text  [Select][+][-]
  1.  // Combinaisons tried
  2.  
  3. <option value="222.222.222.0"     {{[IF(comparetext(mask,    '222.222.222.0')=0, 'selected','')]}}> 222.222.222.0   </option>  
  4. <option value="222.222.222.0"     {{[IF(comparetext(mask,    '222.222.222.0')=0, 'selected','')]}}> 222.222.222.0   </option>  
  5. <option value="222.222.222.0"     {{[IF(mask='222.222.222.0', 'selected','')]}}> 222.222.222.0   </option>  
  6.  
  7.  
the lazarus code is :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   //fpMus := TMustache.Create(Self);
  4.   fpMusEx := TMustacheExpr.Create(Self);
  5.   fpMusEx.RegisterVariables(mmJson.Text, 'host');     // mmJson = memo that containe the json data
  6. end;
  7.  
  8. procedure TForm1.Button1Click(Sender: TObject);
  9. begin
  10.   fpMusEx.Template := mmTemp.Text;                       // mmTemp = memo that containe template data.
  11.   mmRes.Text := fpMusEx.Render(mmJson.Text);
  12. end;
  13.  

Heeeeeelp please.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

BSaidus

  • Sr. Member
  • ****
  • Posts: 495
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: fpweb/weblaz questions.
« Reply #10 on: April 15, 2023, 12:16:52 pm »
I think there is a bug in the fpc-mustache packege.
try this attached exemple.

fpc 322 & lazarus 2.6
« Last Edit: April 15, 2023, 01:02:01 pm by BSaidus »
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

 

TinyPortal © 2005-2018