Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

redirect after popup close

I am displaying a form that is popped up via the style popup. The form shows up as expected. Following the user submission of data I am trying to redirect (e.g. /Discussions). The effect I get is that the redirection is shown on the Informmsg overlay rather than "full screen". I suspect that the popup form (which Vanilla implements as an overlay) interferes with the process.

I will provide code if required, but it would take time to extract it from the original, so I hope the above explanation is sufficient.
Thanks in advance!

Comments

  • BleistivtBleistivt Moderator

    Try setting a redirect url instead of using redirect().

    $sender->RedirectUrl = url('discussions');
    
  • rbrahmsonrbrahmson ✭✭✭

    Thank you @Bleistivt, that worked.

    BUT, to be honest, I was asking for an Aspirin when I had a flu;-) The real problem is that without redirection whatever I display (echo) following the display and submission of the popped up form is not shown full screen. Form->close() didn't do it. I also tried to attach a Javascript close script to the submit button but that is not a good solution if I want to display an error message on the form post submission (validation...).

    _So I wonder what is the proper technique to close a popped up form and proceed normally . _

    Appreciate any suggestions (the routing solution is working, but is just wrong...)

  • R_JR_J Admin

    If you see a form, php is already done with rendering. That's why every echo can have no effect.

    If you want to "close the form and proceed", you need JavaScript. PHP cannot change a page. It only does the initial rendering.

  • rbrahmsonrbrahmson ✭✭✭

    OK, insightful but in the authenticatedPostBack mode logic (which obviously is post submission) I do two things:
    A. Validate some values and sometimes want to redisplay the form (still in popup state) with an error message. That doesn't work if the JavaScript closed the form after a button is pressed. So how do I close it from php while processing authenticatedPostBack rather than from within (JavaScript attached to the button)? BTW, the term "close" may be misleading because it's not a true window - I used the browser inspector and see what happens - the popup form is implemented through a semi-transparent overlay and another layer for the form, all the while hiding the original content area. What I did put in my button-attached JavaScript is:

    $( "div" ).remove( ".Overlay" );
    $( "div" ).remove( "@Popup" );
    

    B. Proceed with something else based on the user input. Whatever is about to be shown (e.g. /discussions) should appear full screen. Works if I JavaScript closed the form, but see #1 above... If I don't close it, the output is not full screen.

  • R_JR_J Admin

    If you want to add validation results, you have to do this by JavaScript. Look at the html of a form with errors:

    <form action="/plugin/something?" method="post">
      <div>
      <input id="Form_TransientKey" type="hidden" value="blubb" name="TransientKey">
      <input id="Form_hpt" type="hidden" style="display: none;" value="" name="hpt">
      <div class="Messages Errors">
        <ul>
          <li>Some Error Message</li>
        </ul>
      </div>
    

    You would have to make that call as an AJAX call to a custom function and return error if needed. Then you would have to write js which adds your error messages in such a div.Messages.Errors
    If there are no errors, you could show a success popup (with js again)

    Vanilla is improving their form management so that you could expect you can do this with simply adding the right classes in the future, but what's happening behind the scenes will be what I've described above (only more elegant)

  • rbrahmsonrbrahmson ✭✭✭

    Thanks! I think that given my priorities I'll stick with the bypass (route) method for now and wait for a better form handling.

  • R_JR_J Admin

    I was looking for something similar recently, because I wanted to put a form in a module. I ended reloading the page since I'm not fluent in JavaScript and had no interest in solving the problem "manually" and I felt it was no bad UI at this place.

    I guess you should understand that doing it with JavaScript is the only way to handle this and it's called AJAX and it is nothing new ;)

  • rbrahmsonrbrahmson ✭✭✭

    Yes, @R_J, I understand. I actually found a work around the validation and popup that I am testing on a newer version of the DiscussionTopc plugin. Watch for it very soon;-)

  • If your problem is how to add a form, any form you want to open in a popup, Look at

    this code for My Contact plugin . I made a contact form that submits an email to the admin or whatever email you have as the forum email in it's own page that adds a link in the menu to that page where the form is. Then I converted it into a popup by adding the class to it in this fashion. The only drawback or gain is that the link only shows to logged in users. The Contact plugin also shows an easy format of validation and submission. It could be of help to you .

    $Sender->Menu->AddLink('Contact',T('Contact'), 'plugin/Contact',array(),array(),array('class'=>'Popup'));

  • rbrahmsonrbrahmson ✭✭✭

    Thanks @vrijvlinder, I know how to create forms and form-validate. I will look at your plugin for possible additional insights.

Sign In or Register to comment.