Advanced Forms Addon

Permalink 2 users found helpful
Hi Together,

I already posted this issue in the advanced forms addon forum but haven`t received a satisfying answer yet.

I am using the "redirect to a specific URL after submit" feature of the addon. Redirection works fine and by default opens in the same window. I would like to have the redirect opened in a new window. According to the developer it`s possible, but modifications are neccessary.

Does anyone else using this addon know an answer or had the same "problem"? As I am a complete noob with Javascript and .php, I would highly appreciate, if someone could help me.

Thank you and regards,

Kat

View Replies: View Best Answer
planist1 replied on at Permalink Reply
planist1
This might be a step in the right direction:

So if the settings of your form is set to redirect to another page on the site, you could do the following:

create a folder called templates in the root/packages/sixeightforms/blocks/sixeightforms folder.

copy the root/packages/sixeightforms/blocks/sixeightforms/view.php file to the root/packages/sixeightforms/blocks/sixeightforms/templates folder

rename the root/packages/sixeightforms/blocks/sixeightforms/templates/view.php file to let's call it new_window.php

replace lines 303-306 from this

case 'redirect':
                     window.location = response.response;
                     break;


to this:

case 'redirect':
$redirectlocation = response.response;
                     window.open($redirectlocation);
                     break;


then after you have added your form to the page, click on it, select custom template, choose, New Window.
effweb replied on at Permalink Reply
Thank you very much for your awesome reply. Worked out well!

Only thing that "bothers" me now is, that the popup gets blocked (depending on browser settings). Is it possible to do the same thing
with a "=target_blank" instruction or something else to avoid the blocking?
planist1 replied on at Permalink Reply
planist1
This might fix that problem.

case 'redirect':
                     $redirectlocation = response.response;
                     window.open($redirectlocation,'','_blank');
                     break;
effweb replied on at Permalink Reply
Thanks again.

Unfortunately this didn`t work. As far as I understand it, the window.open function will always open a popup that might get blocked.

Is it possible to keep the window.location function and put the "target=_blank" into the form tag to open a new window/tab?
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
I think something like this will work:
case 'redirect':
      $redirectlocation = response.response;
      echo '<a id="redirect_link" href="'.$redirectlocation.'" target="_blank" style="display: none">Location</a>
      <script type="text/javascript">
          $(document).ready(function(){
              $("#redirect_link").click();
          });
      </script>';
      break;


I'm not sure whether it will work or not but have it a try.

Rony
effweb replied on at Permalink Reply
Many thanks for your reply, Rony!

I gave it a try but it didn`t work. Redirection occurs in the same window.

I am not quite sure, but there seems to be something wrong with the syntax. There is no error message from the system, but parts of the source code following the </script> tag were displayed on the site right above the form.
planist1 replied on at Permalink Reply
planist1
So I think I managed to get this or at least part of the way.

For your form settings, Choose Display a message. Then in the message box put

<a href="http://www.cnn.com" target="_blank" id="redirected_link" > </a>

of course changing the url to whatever.

Then in the root/packages/sixeightforms/blocks/sixeightforms/templates/view.php

modify the case for thank you (line 292) to this.

case 'thankyou':
                     $('#sem-form-<?php  echo $bID; ?>').fadeOut('fast',function() {
                        <?php   if($displayInDialog != 1) { ?>
                           $('#sem-form-response-<?php  echo $bID; ?>').html(response.response);
                           $(document).ready(function()   
                              {
                                 if ($('#redirected_link').length >0)
                                    {
                                       $("#redirected_link")[0].click();
                                    }
                                    else
                                    {
                                    }
                              });
                        <?php   } ?>
planist1 replied on at Permalink Best Answer Reply
planist1
Scratch my previous post at it has the same problem with the pop-up as before.

Perhaps we should try a more direct approach.

Like modifying the form .

Try changing line 475 of root/packages/sixeightforms/blocks/sixeightforms/templates/view.php to

<form class="sem-form <?php  echo $f->properties['handle']; ?>" id="sem-form-<?php  echo $bID; ?>" enctype="multipart/form-data" method="post" onSubmit="window.open('http://www.cnn.com');" action="<?php  echo $uh->getToolsURL('process_form','sixeightforms'); ?>">


This way it will not matter what you select in the form settings.
effweb replied on at Permalink Reply
The last one nailed it. Thank you very much!

I tried the other solution as well, but it got blocked (just as you mentioned).
So, if I have like 20 or 30 forms I want to redirect, I will have to create a specific template view.php for each of them?
planist1 replied on at Permalink Reply
planist1
Wohoo! I think so. Assuming they are going to different urls. If they are going to the same url, then you could use the same template.
planist1 replied on at Permalink Reply
planist1
Oh and make sure to select the best answer so that others can find it.
effweb replied on at Permalink Reply
I sure will:-)
Once again, thanks for the great help!
effweb replied on at Permalink Reply
Hi again,

while the thing itself works perfectly fine, I recently found out, that through the redirection any required data of the form gets ignored. You can press the submit button without filling out anything and the redirection takes place. This is messing up my statistics....

Does anyone have a suggstion how to fix this?
JohntheFish replied on at Permalink Reply
JohntheFish
I think you have run into a basic limitation of web servers. When you redirect to another url, any get or post data attached to the original request doesn't automatically get passed through to the redirected request.
ssdscott replied on at Permalink Reply
ssdscott
I have been having a problem with trying to log debug data in a function that does a re-direct at the end, and stumbled upon this while researching that. Does this comment imply (as I believe it might) that by doing a redirect, I lose the log statements from the header?

Here's my boiled down to the minimum problem function. With the redirect commented out, I get logs. With it enabled, no logs, and it does the redirect as asked.

public function saveReally() {
        FB::log('in saveReally ');
        $data = $_POST;
        $div = $data['div_id'];
        $season = $data['season_num'];
        FB::log('redirect ' . $div . '/' . $season);
//        $this->redirect('/dashboard/scoring/view_div/' . $div . '/' . $season . '/');
    }


Thanks John - you've helped me dozens & dozens of times with posts you've made in the past :)
JohntheFish replied on at Permalink Reply
JohntheFish
Yes, that is exactly the limitation you have run into.

If all you are looking for is some diagnostics while developing, you can add direct to the c5 log.

See
http://www.concrete5.org/documentation/how-tos/developers/concrete5...

You can then view the log in the dashboard.

For convenience, you can also add a log viewing block to a page and it will then retrieve and show the latest log entries, no matter how many redirects happen in between.
http://www.concrete5.org/marketplace/addons/quick-log-view/...