Is there a PHP IsSet() in Modharbour

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

Is there a PHP IsSet() in Modharbour

Postby reinaldocrespo » Tue Mar 28, 2023 7:18 pm

Hello friends;

I'm trying to stop writing any new PHP. Instead I want to try to use mod harbour. Look at this simple sample code below and help me translate the <php> part to <prg> mod harbour. PHP function IsSet() simply tells the script if a value exists in the POST hash like using hb_isHash( h ) .and. hhaskey( h, 'accept' ).

Can someone help?

Code: Select all  Expand view

<!DOCTYPE html>
<html>
  <head>
    <title>Buttons with Actions</title>
    <style>
      /* Styling for the buttons */
      .button {
        display: inline-block;
        padding: 10px 20px;
        font-size: 16px;
        border-radius: 5px;
        cursor: pointer;
      }
      .accept {
        background-color: green;
        color: white;
      }
      .cancel {
        background-color: red;
        color: white;
      }
    </style>
  </head>
  <body>
    <h1>Hello there!</h1>
    <p>Please click on one of the buttons below:</p>
    <form method="post">
      <button class="button accept" type="submit" name="accept" value="true">Accept</button>
      <button class="button cancel" type="submit" name="cancel" value="true">Cancel</button>
    </form>

    <?php
      if (isset($_POST['accept'])) {
        // execute some action when accept button is clicked
        echo "<p>You clicked the accept button.</p>";
      } elseif (isset($_POST['cancel'])) {
        // execute some action when cancel button is clicked
        echo "<p>You clicked the cancel button.</p>";
      }
    ?>
  </body>
</html>

 
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Is there a PHP IsSet() in Modharbour

Postby Carles » Wed Mar 29, 2023 5:42 am

Reinaldo,

Code: Select all  Expand view
function Main()

TEMPLATE
    <!DOCTYPE html>
    <html>
      <head>
        <title>Buttons with Actions</title>
        <style>
          /* Styling for the buttons */
          .button {
            display: inline-block;
            padding: 10px 20px;
            font-size: 16px;
            border-radius: 5px;
            cursor: pointer;
          }
          .accept {
            background-color: green;
            color: white;
          }
          .cancel {
            background-color: red;
            color: white;
          }
        </style>
      </head>
      <body>
        <h1>Hello there!</h1>
        <p>Please click on one of the buttons below:</p>
        <form method="post">
          <button class="button accept" type="submit" name="accept" value="true">Accept</button>
          <button class="button cancel" type="submit" name="cancel" value="true">Cancel</button>
        </form>
ENDTEXT

   
    if HB_HHasKey( AP_PostPairs(), 'accept' )
        ? "<p>You clicked the accept button.</p>"
    elseif HB_HHasKey( AP_PostPairs(), 'cancel' )
        ? "<p>You clicked the cancel button.</p>"
    endif


TEMPLATE
     </body>
    </html>

ENDTEXT

RETU nil


Review the examples in the samples folder. There is everything you need


Regards.
C.
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1090
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: Is there a PHP IsSet() in Modharbour

Postby Ruth » Thu Nov 09, 2023 12:07 pm

Dear friends,
maybe you could help me with this please...
I am attempting to dynamically reference a hash table using the variable name "cHashName" but I keep receiving an error stating "variable does not exist" in condition nr.3 in the code i provided.
nr. 1 and nr. 2 are working fine but I have something wrong in nr. 3.
I would really appreciate your expertise.
Thank you so much for your time and help.
Ruth

Code: Select all  Expand view

hTables := {=>}
hTables["hSTARS"] := hSTARS
cHashName := ALLTRIM(hBLOCK["PAGE_VERZEICHNIS2"])      

//nr.1 working fine
IF HB_HHasKey( hSTARS, LTRIM( STR( 1 ) ) + "_MORELINK" )
  ? "working with hSTARS hardcoded"
ENDIF

//nr.2 working fine
IF HB_HHasKey(hTables[cHashName], LTRIM( STR( 1 ) ) + "_MORELINK")
  ? "working with hTables[cHashName]"
ENDIF


//nr.3 giving me an error "variable does not exist"
IF HB_HHasKey(&cHashName, cKey)
  ? "working with &cHashName"
ENDIF
 
User avatar
Ruth
 
Posts: 135
Joined: Fri Dec 07, 2007 1:26 pm

Re: Is there a PHP IsSet() in Modharbour

Postby Antonio Linares » Thu Nov 09, 2023 12:29 pm

Dear Ruth,

Please add this line above step 3:

Code: Select all  Expand view
? cHashName
IF HB_HHasKey(&cHashName, cKey)
  ? "working with &cHashName"
ENDIF


and let us know what you get, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Is there a PHP IsSet() in Modharbour

Postby Ruth » Thu Nov 09, 2023 1:23 pm

Image
Dear Antonio, thank you so much for your attention.
I get "hSTARS" for it.
Kind regards
Ruth
Code: Select all  Expand view


hTables := {=>}
hTables["hSTARS"] := hSTARS
cHashName := ALLTRIM(hBLOCK["PAGE_VERZEICHNIS2"])      

IF HB_HHasKey(hTables[cHashName], LTRIM( STR( 1 ) ) + "_MORELINK")
  ? "working with hTables[cHashName]"
ENDIF

IF HB_HHasKey( hSTARS, LTRIM( STR( 1 ) ) + "_MORELINK" )
  ? "working with hSTARS hardcoded"
ENDIF

? "cHashName:", cHashname
IF HB_HHasKey(&cHashName, cKey)
  ? "working with &cHashName"
ENDIF
User avatar
Ruth
 
Posts: 135
Joined: Fri Dec 07, 2007 1:26 pm

Re: Is there a PHP IsSet() in Modharbour

Postby Antonio Linares » Thu Nov 09, 2023 3:11 pm

Dear Ruth,

hStars must be declared as public:

public hStars

so the "macro" operator can locate and use it

best regards
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Is there a PHP IsSet() in Modharbour

Postby Ruth » Thu Nov 09, 2023 8:27 pm

Dear Antonio,

this is AMAZING!!! Thank you so very much for help!!!
Now everything is working fine :-)
https://bergland.info/index.prg?recnr=18

Kind regards, many thanks again and have a nice evening
Ruth

Image

Code: Select all  Expand view
<div class="tags-area my-4">
            <div class="mb-2">
              $->  TAGS : cKey=1; cHash=&cHashName
              $->  TAGS : cKey=2; cHash=&cHashName
              $->  TAGS : cKey=3; cHash=&cHashName
              $->  TAGS : cKey=4; cHash=&cHashName
              $->  TAGS : cKey=5; cHash=&cHashName
              $->  TAGS : cKey=6; cHash=&cHashName
             
            </div>
          </div>

Code: Select all  Expand view
ENDTEXT

cHashName := ALLTRIM(hBLOCK["PAGE_VERZEICHNIS2"])      

IF HB_HHasKey( &cHashName, LTRIM( STR( |cKey| ) ) + "_MORELINK" )


TEMPLATE PARAMS hPageData, hHash_MENU,  hSLIDER,  hHEADLINES_STARTSCREEN_BOTTON, hDISCOVER, hTRENDING, hCENTER, hSTARS, hFOOTER_A, hFOOTER_B, hTIPPS, hFOOTER_D, hARTICLES, hFEATURED_ARTICLES, hFEATURED_RIGHT, hSLIDER_TICKER, hGRID_SLIDER_1, hTRAVELLING, hMOST_READ, hBLOCK
   
   
   
 
 
  <a class="btn btn-outline-primary btn-sm rounded-0 me-2 mb-2"
  href='<?prg return |cHash|[ LTRIM( STR( |cKey| ) ) + "_MORELINK" ] ?>'><?prg return |cHash|[ LTRIM( STR( |cKey| ) ) + "_HEADER" ] ?></a>


  ENDTEXT



ENDIF

TEMPLATE PARAMS hPageData, hHash_MENU,  hSLIDER,  hHEADLINES_STARTSCREEN_BOTTON, hDISCOVER, hTRENDING, hCENTER, hSTARS, hFOOTER_A, hFOOTER_B, hTIPPS, hFOOTER_D, hARTICLES, hFEATURED_ARTICLES, hFEATURED_RIGHT, hSLIDER_TICKER, hGRID_SLIDER_1, hTRAVELLING, hMOST_READ, hBLOCK
 
User avatar
Ruth
 
Posts: 135
Joined: Fri Dec 07, 2007 1:26 pm


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 7 guests