This is a complex question so I'll try and be precise.
I've experimented with AJAX but this form requires many changes to do it. I'd like to know if there are other options.
I have a form which takes a very long time to complete. Let's say the form exists on page A. The form submits and calls page B.
Page B looks like this, and gives the incorrect result (the page appears blank while loading):
<html>header</html>
<?php
longformresult()
?>
If I setup the page like this I get the result I am looking for (the page waits until the long function is done to load the page, allowing me to display a loading screen on page A).
<?php
longformresult()
?>
<html>header</html>
however this is where things get really tricky, the longformresult() can fail and break everything below it.
Is there some way I can tell php to wait until the page is fully loaded before sending the page, allowing me to have a loading screen on page A? Or prevent a die() from killing my page? I essentially need to delay the appearance of Page B, and actually just a sleep() is probably the best approach I've had so far:
<?php
sleep(4)
?>
<html>header</html>
<?php
longformresult()
?>
Edit: Conclusion (Not the fix I was looking for though)
I used ajax and removed 'Page B' entirely.