Pasar variable al .prg

mod_harbour es un módulo para Apache que permite correr tus PRGs directamente en la web!!!

Pasar variable al .prg

Postby acuellar » Tue Aug 31, 2021 7:44 pm

Buenas estimados

Cómo se hace para pasar una variable al programa.prg desde el index.html
Code: Select all  Expand view

<a href="programa.prg">Pasa variable</a>
 


Gracias por la ayuda
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Pasar variable al .prg

Postby Otto » Tue Aug 31, 2021 8:12 pm

Adhemar, attached a sample.
Best regards,
Otto

Code: Select all  Expand view

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

//----------------------------------------------------------------------------//
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Pasar variable al .prg

Postby acuellar » Tue Aug 31, 2021 9:20 pm

Thanks Otto

show me
Code: Select all  Expand view

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: Select all  Expand view

 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.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Pasar variable al .prg

Postby Otto » 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: Select all  Expand view

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: Select all  Expand view


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() )
 
   
? "--------------------------------------"
   
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Pasar variable al .prg

Postby Otto » Tue Aug 31, 2021 11:50 pm

Adhemar, or to the same page

program.prg

Code: Select all  Expand view


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

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

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Pasar variable al .prg

Postby Otto » Wed Sep 01, 2021 10:26 am

Adhemar, I extended the sample to show POST and GET methods.

program1.prg

Code: Select all  Expand view


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

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

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Pasar variable al .prg

Postby acuellar » Wed Sep 01, 2021 2: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.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Pasar variable al .prg

Postby Otto » Wed Sep 01, 2021 8:23 pm

Adhemar,

What do you want to do with index.html?

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Pasar variable al .prg

Postby acuellar » 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.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Pasar variable al .prg

Postby Otto » Wed Sep 01, 2021 11:55 pm

********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Pasar variable al .prg

Postby Antonio Linares » Thu Sep 02, 2021 4:39 am

You have to create a .htaccess file with this content (thanks to Charly):

Code: Select all  Expand view
# --------------------------------------------------------------------------
# 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41335
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Pasar variable al .prg

Postby acuellar » 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.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 2 guests