We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30285
    • 2 Posts
    Hi,
    I’m having trouble using the snippets. I’m not a programmer by any means but I was able use the following code to display a form on a regular page when it’s not run through modx. When I try to make it work with snippets nothing even displays, i’m pretty sure it has something to do with returning values but I don’t know how to go about it.

    Here’s what I have before any html
    [tt]<?php

    session_start();
    require($DOCUMENT_ROOT.’/partyrsvp/func.php’);

    $c = connect_db();

    $output = "";

    if($_POST[’submitted’] == "submitted" && ($_POST[’fname’] != "" || $_POST[’lname’] != "") && ctype_digit($_POST[’pid’]))
    {
    parsvp(mysql_real_escape_string($_POST[’fname’]),
    mysql_real_escape_string($_POST[’lname’]),
    mysql_real_escape_string($_POST[’phone’]),
    mysql_real_escape_string($_POST[’email’]),
    mysql_real_escape_string($_POST[’guests’]),
    mysql_real_escape_string($_POST[’pid’]),
    mysql_real_escape_string($_POST[’bday’]),
    $id,
    $c);

    $output .= "Thank you. You have been RSVP’d for the party! See you there!";
    }
    else
    {
    $output .= addpar_form("1", $c);
    }

    close_db($c);

    ?>[/tt]


    ...And I stick this wherever I want the form displayed

    [tt]<?=$output?>[/tt]

    Do I have to create two different snippets for these two parts?
    How can I make this work? Thank you in advance. huh
      • 32982
      • 674 Posts
      put in the only one snippet in the end return $output;
      and call the snippet in a template...
        Jabiertxof (formerly XYZVISUAL)
        My bussines: http://marker.es
        https://www.youtube.com/user/jabiertxof/videos
        • 25663 MODX Staff
        • 12,272 Posts
        Only try to avoid using short PHP tags as that can break in many situations.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Have the last action of your snippet be "return $output", then put the snippet tags where you want that output to appear, just as you normally would with the <?php...?> tags.
            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
            • 30285
            • 2 Posts
            cool i got it working, thanks guys, really quick response smiley