We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46738
    • 3 Posts
    I try to run a form in Modx Revo that the form action="" then runs a PHP snippet which inserts the input name="" into a url, that page is then parsed and inserted into the db and results are to be displayed on the same page as the form. My problem is the script is either not reading the form input or the script isn't running at all.

    My form is as follows:

    <form action="[[!charAll]]" method="post">Character: <input type="text" name="char" /><br /> Realm:      <input type="text" name="realm" /><br /> <input type="submit" /></form>


    My snippet script is pretty long but I will give some of it for illustration.(table names have been changed for security.

    $realm = $_POST["realm"];
    $char = $_POST["char"];
    
    $realm = rawurlencode($realm);
    @$mstats = file_get_contents("http://us.battle.net/api/wow/character/$realm/$char?fields=statistics,achievements", true);
    $pvp = json_decode($mstats, true);
    
    $link = mysqli_connect("127.0.0.1","dbuser","dbpw","dbname") or die("Error " . mysqli_error($link));
    $link->set_charset("utf8"); 
    
    $mname = $link->real_escape_string($pvp['name']);
    $mmrealm = $link->real_escape_string($pvp['realm']);
    $mclass = $pvp['class'];
    $mrace = $pvp['race'];
    $mgender = $pvp['gender'];  
    $mlvl = $pvp['level'];
    $mid = $pvp[""];
    
    
    $query5 = "INSERT INTO char_1 ( character_id, name, server, class, race, gender, level )
    VALUES ('$mid', '$mname', '$mmrealm', '$mclass', '$mrace', '$mgender', '$mlvl')";
    $result5 = $link->query($query5) or die("Error in the consult 1.." . mysqli_error($link));
    
    $awon = $pvp['statistics']['subCategories'][9]['subCategories'][0]['statistics'][0]['quantity'];
    $aplyd = $pvp['statistics']['subCategories'][9]['subCategories'][0]['statistics'][1]['quantity'];
    $hpr2v2 = $pvp['statistics']['subCategories'][9]['subCategories'][0]['statistics'][24]['quantity'];
    $hpr3v3 = $pvp['statistics']['subCategories'][9]['subCategories'][0]['statistics'][23]['quantity'];
    $hpr5v5 = $pvp['statistics']['subCategories'][9]['subCategories'][0]['statistics'][22]['quantity'];
    $rbgWon = $pvp['statistics']['subCategories'][9]['subCategories'][1]['statistics'][35]['quantity'];
    $rbgPlyd = $pvp['statistics']['subCategories'][9]['subCategories'][1]['statistics'][33]['quantity'];
    $hks = $pvp['totalHonorableKills'];
    ...runs a few other queries, then echo's
    the results like the following as an example...
    echo " <div width='1222px' align=\'left\' valign=\'top'\ >";
    echo "
    <div align=\"left\" id=\"roster\" class=\"roster\">
    <table class='warcraft sortable' width=\"1222px\" border=\"3\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
       <tr>
        <th class='sorttable_nosort'><width=\"50\" align=\"center\"><strong>Race/Class</strong></th>
        <th class='sorttable'><width=\"200\" align=\"center\"><strong>Name</strong></th>
        <th width=\"30\" align=\"center\"><strong>Lvl</strong></th>
    	<th class='sorttable_nosort'><width=\"100\" align=\"center\"><strong>XPRank</strong></th>
    	<th width=\"60\" align=\"center\" ><strong>PVPAP</strong></th>
    	<th width=\"60\" align=\"center\" ><strong>ARAP</strong></th>
    	<th width=\"60\" align=\"center\" ><strong>RBGAP</strong></th>
    	<th width=\"60\" align=\"center\" ><strong>ARPLD</strong></th>
    	<th width=\"60\" align=\"center\"><strong>ARWON</strong></th>
    	<th width=\"60\" align=\"center\"><strong>HPR2v2</strong></th>
    	<th width=\"60\" align=\"center\"><strong>HPR3v3</strong></th>
    	<th width=\"60\" align=\"center\"><strong>HPR5v5</strong></th>
    	<th width=\"60\" align=\"center\"><strong>RBGPLD</strong></th>
    	<th width=\"60\" align=\"center\"><strong>RBGWON</strong></th>
    	<th width=\"60\" align=\"center\"><strong>PvpXP</strong></th>
    	<th width=\"60\" align=\"center\"><strong>HKs</strong></th>
       </tr>
    ";
    an array result then...
    echo "
       <tr>
        <td align=\"center\"><strong><img style=\"padding-left: 3px;\" src=\"img/race/$mrace-$mgender.gif\"></img><img style=\"padding-left: 3px;\" src=\"img/class/$mclassid.gif\"></img></strong></td>
        <td class='class_$mclassid' width=\"200\" align=\"left\"><strong>$mname</strong></td>
        <td class='class_$mclassid' width=\"30\" align=\"center\"><strong>$mlevel</strong></td>
    	<td class='class_$mclassid' width=\"100\" align=\"center\"><strong>$rank</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\" ><strong>$pvpp</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\" ><strong>$arp</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\" ><strong>$rbgp</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$aplyd</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$awon</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$hpr2v2</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$hpr3v3</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$hpr5v5</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$rbgPlyd</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$rbgWon</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$pvpXP</strong></td>
    	<td class='class_$mclassid' width=\"60\" align=\"center\"><strong>$hks</strong></td>
       </tr>
    ";
    }
    echo " ";


    The script runs fine outside of Modx so I know the script is working and so is the form, I just can't seem to get it to work in Modx.

    I know Modx Revo will be great once I get the hang of it but atm it is giving me a headache lol, I am very new to web dev and even newer to Modx, any help would be greatly appreciated and I thank you in advance.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It may take a little time at first to learn, but you really should build a proper xPDO schema and object for your database, then use the MODX database API for manipulating it. To begin with, examine how MODX accesses its own objects, such as users or resources. As a shortcut, you can use MIGXdb. Whether you use MIGXdb or not, this will give you a much more robust and elegant system for managing your player database (which is pretty much what this is all about).
      http://bobsguides.com/revolution-objects.html
      http://bobsguides.com/custom-db-tables.html
      http://www.youtube.com/watch?v=Dv83iC9iELI
      http://www.bdcreative-design.com/blog/creating-a-cmp-in-modx-using-migxdb/
      http://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials

      There are also several tutorials on creating a proper schema from existing database tables, which is certainly a lot easier than hand-coding the schema XML files!
      http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/reverse-engineer-xpdo-classes-from-existing-database-table
      http://rtfm.modx.com/xpdo/2.x/class-reference/xpdogenerator/xpdogenerator.writeschema

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 46738
        • 3 Posts
        I agree I will eventually need a better system for managing my database and I will definitely look into the links you have provided, while the current system I am using will work alright for low traffic it would choke with multiple high volume.

        What I am trying to build is a site players can go to and look up their pvp statistics, and while I have managed to do it for my guild site http://worldpvp.pvpxp.com/members.php where I can simply cache contents and update every hour, this will be a single character look up with possibly multiple users looking up characters at the same time, so database management will be a major factor.

        Thank you for the response, I am always happy to here from those more knowledgeable than I.
        ...now if I can just get my form to work. smiley
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You could "cheat" and just use MODX users. Since your external source appears to return a JSON string, that would be a short cut since the user extended fields are stored as a JSON string by MODX.

          http://rtfm.modx.com/extras/revo/login/login.tutorials/login.using-custom-fields
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 46738
            • 3 Posts
            I have checked out the links you have provided and have found them to be extremely useful. MIGXdb will indeed prove to be an invaluable tool as well as the tutorials you have listed. It opened my mind to the fact that I was approaching Modx with the mindset of how I could get it to do what I want rather than trying to learn it and let it help me in return.

            I have no doubt that Modx will be a tremendous tool that will help me once I have gotten past the learning curve.
            Though I am fairly new to development I have already tried several other CMS's to get a 'feel' for them, most left me so frustrated at the lack of flexibility that I built my guild website without a CMS and just used my raw code. Modx seems to be the most flexible and very well shows it's potential to keep up as my demand increases in the future. It is definitely worth the time I will be spending in the 'learning curve' phase.

            Again thank you for your response and invaluable advice.