FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index mod_harbour Pasar variable al .prg
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Pasar variable al .prg
Posted: Tue Aug 31, 2021 07:44 PM
Buenas estimados

Cómo se hace para pasar una variable al programa.prg desde el index.html
Code (fw): Select all Collapse
<a href="programa.prg">Pasa variable</a>


Gracias por la ayuda
Saludos,



Adhemar C.
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Pasar variable al .prg
Posted: Tue Aug 31, 2021 08:12 PM
Adhemar, attached a sample.
Best regards,
Otto

Code (fw): Select all Collapse
function main
local cTest := "my Test"

TEMPLATE PARAMS cTest

<!DOCTYPE html>
<html>
<head>
    <style>
        body {background-color: powderblue;}
        h1   {color: blue;}
        p    {color: red;}
    </style>
</head>
<body>
    
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
    
    <a href="programa.prg">Pasa variable <?prg return cTest ?></a>
</body>
</html> 

ENDTEXT

return 

//----------------------------------------------------------------------------//
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Pasar variable al .prg
Posted: Tue Aug 31, 2021 09:20 PM
Thanks Otto

show me
Code (fw): Select all Collapse
This is a heading
This is a paragraph.

Pasa variable My test


And program.prg does not receive the variable

or as it is put in program.prg to receive it

I need to go to the same program from two buttons

Code (fw): Select all Collapse
 cTest="L"
<a href="program.prg">Muestra libres <?prg return cTest ?></a>
 cTest="O"
<a href="program.prg">Muestra ocupadas <?prg return cTest ?></a>

In Program.prg
  USE (  PATH_DATA+'base.dbf' ) SHARED NEW VIA 'DBFCDX'
  INDEX ON field->nombre TAG "nombre" FOR field->tipo=cTest MEMORY

thanks for your time and help

Best regards,
Saludos,



Adhemar C.
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Pasar variable al .prg
Posted: Tue Aug 31, 2021 11:44 PM
Adhemar, I think I misunderstood the question.
You mean you want to pass a variable from program.prg to another prg or the same?
Best regards,
Otto

Code (fw): Select all Collapse
function main
local cTest := "my Test"

TEMPLATE PARAMS cTest

<!DOCTYPE html>
<html>
<head>
    
</head>
<body>
    
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
    
    
    <a href="postpairs.prg?test=<?prg return cTest ?>">Pasa variable <?prg return cTest ?></a>
</body>
</html> 

ENDTEXT

return 

//----------------------------------------------------------------------------//


postpairs.prg


Code (fw): Select all Collapse
function Main()
 
? "--------------------------------------"
   ? "AP_FileName() --> cFileName   returns the filename.prg provided to Apache by the client"
   ? ValToChar(AP_FileName())
     
  
   ? "AP_GetPairs() --> Hash    returns a hash with all GET pairs, key and value "
   ? ValToChar(AP_GetPairs())
  
   ? "AP_Args() --> cArgs   returns the args provided to Apache by the client if any "
   ? ValToChar( AP_Args() )
  
    
? "--------------------------------------"
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Pasar variable al .prg
Posted: Tue Aug 31, 2021 11:50 PM
Adhemar, or to the same page

program.prg

Code (fw): Select all Collapse
function main
local cTest := "my Test"
local cTest2 := "my Test lorem ipsum"

 
? "--------------------------------------"
   ? "AP_FileName() --> cFileName   returns the filename.prg provided to Apache by the client"
   ? ValToChar(AP_FileName())
     
  
   ? "AP_GetPairs() --> Hash    returns a hash with all GET pairs, key and value "
   ? ValToChar(AP_GetPairs())
  
   ? "AP_Args() --> cArgs   returns the args provided to Apache by the client if any "
   ? ValToChar( AP_Args() )
  
    
? "--------------------------------------"
   





TEMPLATE PARAMS cTest, cTest2

<!DOCTYPE html>
<html>
<head>
    
</head>
<body>
    
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
    
    
    <a href="program.prg?test=<?prg return cTest ?>">Pasa variable <?prg return cTest ?></a>
<br>
<a href="program.prg?test=<?prg return cTest2 ?>">Pasa variable <?prg return cTest2 ?></a>


</body>
</html> 

ENDTEXT

return 

//----------------------------------------------------------------------------//
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Pasar variable al .prg
Posted: Wed Sep 01, 2021 10:26 AM
Adhemar, I extended the sample to show POST and GET methods.

program1.prg

Code (fw): Select all Collapse
function main
    local cTest := "my Test"
    local cTest2 := "my Test lorem ipsum"


    ? "<HR>"
    ? "AP_Body()"
    ? AP_Body()
    ? "<HR>"

    ? "AP_Method()"
    ? AP_Method()
    ? "<HR>"

    ? "AP_UserIP() --> cUserIP  returns the IP, as string, of the client"
    ? AP_UserIP() 

    ? "<HR>"
    ? "AP_HeadersIn() //--> Hash    returns a hash with all headers pairs, key and value"
    ? AP_HeadersIn() 

    ? "<HR>"
    ? "AP_FileName() --> cFileName  returns the filename.prg provided to Apache by the client"
    ? ValToChar(AP_FileName())
    ? "<HR>"

    ? "AP_GetPairs() --> Hash   returns a hash with all GET pairs, key and value "
    ? ValToChar(AP_GetPairs())
    ? "<HR>"
    ? "AP_Args() --> cArgs  returns the args provided to Apache by the client if any "
    ? ValToChar( AP_Args() )
    ? "<HR>"
    ? "AP_PostPairs() --> Hash  returns a hash with all POST pairs, key and value"
    ? ( AP_PostPairs() )

    ? "<HR>"
    //AP_RPuts( uValue )    Sends a value, converted into a string, to the client. Returns nil
    AP_RPuts( "<H1>AP_RPUts test</H1><br>" )
    ? "<HR>"




TEMPLATE PARAMS cTest, cTest2

<!DOCTYPE html>
<html>
<head>
    <head>
        <meta charset="utf-8">
        <title>Meine Testseite</title>
    </head>
    
</head>
<body>
    
    <h1>Test  POST and GET</h1>
    <p>This is a test for POST and GET method</p>
    
    <h3>GET  method test</h3>
    <a href="program1.prg?test=<?prg return cTest ?>">Pasa variable - <?prg return cTest ?></a>
    <br>
    <a href="program1.prg?test=<?prg return cTest2 ?>">Pasa variable - <?prg return cTest2 ?></a>
    <br>

    <h3>POST method test - FORM</h3>
    <form action="program1.prg" method="post">
        User name:
        <br>
        <input type="text" name="username">
        <br>
        Password:
        <br>
        <input type="password" name="passw">
        <br><br>
        <input type="submit" value="Send data">
    </form>
</body>
</html> 

ENDTEXT

return 

//----------------------------------------------------------------------------//
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Pasar variable al .prg
Posted: Wed Sep 01, 2021 02:41 PM

Thanks very much Otto

I did it with AP_Args() usando Index.prg

now I'm going to deal with: Index.html

Thanks for your time and help

Saludos,



Adhemar C.
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Pasar variable al .prg
Posted: Wed Sep 01, 2021 08:23 PM

Adhemar,

What do you want to do with index.html?

Best regards,
Otto

Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Pasar variable al .prg
Posted: Wed Sep 01, 2021 10:55 PM

Dear Otto

I want to write: domain/folder and automatically run the index.prg

Don't write: domain/folder/index.prg

Thaknks for your help

Saludos,



Adhemar C.
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Pasar variable al .prg
Posted: Wed Sep 01, 2021 11:55 PM

https://en.wikipedia.org/wiki/Rewrite_engine
Maybe this is a start point.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Pasar variable al .prg
Posted: Thu Sep 02, 2021 04:39 AM
You have to create a .htaccess file with this content (thanks to Charly):

Code (fw): Select all Collapse
# --------------------------------------------------------------------------
# CONFIGURACION RUTAS PROGRAMA  (Relative to DOCUMENT_ROOT)
# --------------------------------------------------------------------------
SetEnv APP_TITLE            "MyApp v1.0a"


# --------------------------------------------------------------------------
# Impedir que lean los ficheros del directorio
# --------------------------------------------------------------------------
Options All -Indexes


# --------------------------------------------------------------------------
# Pagina por defectos
# --------------------------------------------------------------------------
DirectoryIndex index.prg main.prg

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.prg/$1 [L]
</IfModule>
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Pasar variable al .prg
Posted: Thu Sep 02, 2021 11:21 AM

Perfecto.
Muchas gracias Antonio
Thanks Otto

Es un poco complicadito entenderle la lógica de la programación Web.
Pero ya estamos impulsado y lo lograremos :D

Gracias por su tiempo y ayuda.

Saludos,



Adhemar C.

Continue the discussion