Jump to:

23457 Posts in 18905 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Really stupid Function/Variable/Return Question!

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1175 Views
  • LinseyM
    Avatar
    Community Member
    99 Posts

    Really stupid Function/Variable/Return Question! Link to this post

    Hi there,

    Am almost embarrased to ask this as its so simple, but I'm having a brain meltdown here and I've looked through the book but I can't find what I am looking for!

    OK, on page.php I have function:

       function checkMiniFormSub() {
          $showThanks = "";
          if (isset($_GET['formStatus'])){
             $showThanks = "<p>Thank you. Your enquiry has been submitted.</p>";
          }
          echo $showThanks;
       }

    And on the template I had just called the function with:

       <% control checkMiniFormSub %><% end_control %>

    All I want to do is check that a form is submitted and return a thank you message on the page it redirects to.

    It's all working, but obviously because I'm using an echo it is writing the thank you message at the top of the page, and not where its being called in the template!

    So I changed "echo $showThanks;" to "return $showThanks;" but now I have no idea how to get the thank you message to write on the screen via the control as "<% control checkMiniFormSub %>$showThanks<% end_control %>" doesn't work.

    DOH!

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Really stupid Function/Variable/Return Question! Link to this post

    Your right in thinking that should be a return rather than an echo.

    By returning it you can simply use $checkMiniFormSub in the template. $checkMiniFormSub will store the value of the checkMiniFormSub function.

    So if you want it to return false if that text is not set you can do...

    function checkMiniFormSub() {
    return (isset($_GET['formStatus'])) ? "<p>Thank you. Your enquiry has been submitted.</p>" : false;
    }

    Then in the template you can use <% if checkMiniFormSub %>$checkMiniFormSub<% else %>....<% end_if %>

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Really stupid Function/Variable/Return Question! Link to this post

    Thanks Will, worked perfectly. I like how you simplified the function too. Nice. Cheers!

    1175 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.