The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Use View Conditionals to set PHP Variables

Labels

This Discussion is public

Notifications

I have a project where I needed to, via PHP, show a view containing a single entry followed by a form that only appears if the view actually contains something. Normally, one would simply put the form shortcode inside the view and call it a day, but that won't work in this case.

So, how to achieve the same effect without building a complicated set of PHP queries to duplicate the filters on the view?

1. Create a second view (a duplicate of the first). Delete its contents, and replace them with a value like "1" (or for more complicated applications, perhaps the [id] of the returned form entry.
2. Set the "Message if nothing to display" field to be empty.

Then, in PHP:


$gotcontract = FrmProDisplaysController::get_shortcode(array('id' => 520)); // Check to see if we have anything to display in our view.
if($gotcontract != ""){
echo FrmProDisplaysController::get_shortcode(array('id' => 507)); // Display the "real view"
echo FrmFormsController::show_form(30, $key = '', $title=false, $description=true); // Display the form
}
else {
echo "Sorry, there is nothing to display."; // Display "nothing found" message
}

Discussion closed.