We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26031
    • 11 Posts
    Hi,

    I have existing website which has .php pages like order.php, userregistration.php, etc and i have no idea how to make these kind of pages into MODX, i have implemented static pages easily but couldn’t get success to get .php pages into modx. I mainly want to post values on form submit and process that data wether to insert into database or anything else. Main thing is posting values through FORM object, i have tried everything like making chunks, snippets, etc but i am not able to post values. I want to know how do we post values to process them. Normally we use <form> and its action to send values and process but how to do the same thing in modx. Please advice. help me with the simple example please by posting 2 simple values and process them, i mainly want to see posted values. Ta.

    Sami
      • 16886
      • 40 Posts
      Hi Sami30181,
      it’s the same like in your php-code before...

      create your db_access script ( like user,pwd,database ( if it is another database than the modx db ) ) and include it in a SNIPPET
      for example:
      <?php
      include "assets/yourdir/config/db_cfg.php";
      include "assets/yourdir/config/db_functions.php";
      ...
      

      read the url parameters
      for example
      ...
      $myPara=$_GET["Para"];
      ... validate if necessary...
      

      generate your output
      for example
      echo\"<a href=".$_SERVER['PHP_SELF']."?id=".$myPara."&orderaction=buy">myActionName</a>\";
      ...
      ?>
      


      And now the important part:
      Embed your SNIPPET in the document
      for example
      [[mysnippet]]

      be careful, the snippet call must be case sensitive that means, [[mySnippet]] will not work if the generated snippet-name is MYSnippet
      If you want to use the Snippet uncached use:
      [!mysnippet!]


      And don’t forget to free the mysql-db-ressources
      mysql_free_result($yourresult);


      Hope this helps
      Greetings LeftHanded
        I love ModX!
        • 26031
        • 11 Posts
        Hi,

        Thanks for your useful reply, but i am facing difficulties in using form object and also i’m using post method. let me describe my situation and the confusion in my mind:

        1- I don’t know how to architecture my php pages into modx, but i have done something like this, i know this is something stupid but i don’t know anything else: i have created CHUNK to create html form/textboxes/checkbox/textarea/selection box/etc and placed this chunk into page1 (index.php?id=1) in modx .

        2- Ok now i have created the FORM in CHUNK which include diffrent textbox/textarea/selection box/checkbox objects to post it to process just like:

        <form name="form1" id="form1" method="post" action="[~2~]">
        <input name="firstname">
        <input name="lastname">
        <input type="submit" value="submit" name="submit">
        </form>

        you will notice here that i have coded <FORM action="[~2~]"> where the values will be submitted and be processed.

        2- After that i use snippets in page2 (index.php?id=2) which include pure php code to process this data for example:

        <?php
        echo $_POST[’firstname’];
        echo $_POST[’lastname’];
        ?>

        so this is what i am doing and not getting any data posted on page1. dunno how to implement php pages. still confuse, wants to understand modx php implentation architecture. Please help me bit more.

        Ta

        Sami

          • 5340
          • 1,624 Posts
          Use Firefox’s FireBug extension to see if you post correctly

          The console tab should show you what you post
            • 26031
            • 11 Posts
            Hi, Thanks to you all for your useful replies. It seems to me that there was a problem with snippets call.

            I was calling snippets using [[snippets]]

            it seems ok now when i called snippets using [!snippets!]

            Thanks again for your help.

            Ta

            Sami