if else script to control display of form in an iframe.

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 18, 2018   (RSS)

By willydoit - August 17, 2018

Hi all,

I have created a checkbox that clients can check or uncheck to control whether a vacancy enquiry form is displayed within the detail page.

I have tried to create an if else statement to dictate whether the form/iframe is displayed I can get it to display a test message based on 

<?PHP if ($advertisersRecord['show_vacancy_enquiry_form'] == "1") { echo"display form"}

else
{ echo "do not display form"; } ?>

however when i try to use this to control the display of the following code it does not work, the page simply doesn't load.

<script type="text/javascript">
document.write(unescape("%3Ciframe id=\"fb_iframe\" src=\"availability-request.php" + window.location.search + "\" width=\"100%\" height=\"1027\"allowtransparency=\"true\" scrolling=\"no\" frameborder=\"0\"%3E&lt;a href=\"availability-request.php\" title=\"availability-request\"&gt;Check out my CoffeeCup Form&lt;/a&gt;%3C/iframe%3E")); </script>
<noscript> <iframe
height="1027"
style="border:none; background:transparent; overflow:hidden;
width:100%;" id="fb_iframe" src="availability-request/availability-request.html">
<a href="availability-request.php" title="availability-request">Check out my CoffeeCup Form</a>
</iframe> </noscript>

In a nutshell I just want a simple if else script that says if the display box value is 1 show the form, else omit the code and carry on after the form section.  I have tried what I thought was required below but I am obviously missing something. Can anyone see where I am going wrong?

<?PHP if ($advertisersRecord['show_vacancy_enquiry_form'] == "1")
{
<script type="text/javascript"> document.write(unescape("%3Ciframe id=\"fb_iframe\" src=\"availability-request.php" + window.location.search + "\" width=\"100%\" height=\"1027\"allowtransparency=\"true\" scrolling=\"no\" frameborder=\"0\"%3E&lt;a href=\"availability-request.php\" title=\"availability-request\"&gt;Check out my CoffeeCup Form&lt;/a&gt;%3C/iframe%3E")); </script>
<noscript> <iframe height="1027" style="border:none; background:transparent; overflow:hidden; width:100%;" id="fb_iframe" src="availability-request/availability-request.html"> <a href="availability-request.php" title="availability-request">Check out my CoffeeCup Form</a> </iframe> </noscript>
}
else { echo "&nbsp;"; } ?>

Thanks in advance for any/all help provided.

By daniel - August 17, 2018

Hello,

One way to output this sort of HTML block is to close and open the PHP tags before and after it. It would look something like this:

<?PHP if ($advertisersRecord['show_vacancy_enquiry_form'] == "1")
{
?>
<script ...></script>
<noscript>...</noscript>
<?php
}
else { echo "&nbsp;"; } ?>

Let me know if I can help with anything else!

Thanks,

Daniel
Technical Lead
interactivetools.com

By willydoit - August 18, 2018

That has worked beautifully thanks ever so much.