Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

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

Really stupid Function/Variable/Return Question!

Go to End

3 Posts   1906 Views


Community Member, 99 Posts

22 May 2010 at 1:01am

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.


Thanks :)


Forum Moderator, 5523 Posts

22 May 2010 at 9:17pm

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 %>


Community Member, 99 Posts

22 May 2010 at 11:11pm

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