Yii Framework Forum: DESPERATE FOR ADVICE: How do you use a controller to open a new browser tab to display ouput? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

DESPERATE FOR ADVICE: How do you use a controller to open a new browser tab to display ouput? Rate Topic: -----

#1 User is offline   stickdog 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 29-April 10

Posted 02 October 2010 - 04:02 PM

I have a form view in which the user chooses what to display and then hits a submit button. This is working fine.

What I can't figure out is how to use the controller to open a new view on a new browser tab to display the chosen graphical output.

I know this is truly beginning stuff, but I can't find how to do it in the documentation. Would somebody please show me how or point me where to look to figure this out?

Thanks! I really like a lot about this framework.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,358
  • Joined: 12-October 09
  • Location:Croatia

Posted 03 October 2010 - 05:32 AM

To open a link in a new tab add

target="_blank"

to the link...
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   stickdog 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 29-April 10

Posted 03 October 2010 - 01:04 PM

Thanks!
0

#4 User is offline   stickdog 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 29-April 10

Posted 04 October 2010 - 05:06 PM

How do I do this when rendering a view rather than simply making a link?
0

#5 User is offline   Mukke 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 05-September 09
  • Location:Brussels (Belgium)

Posted 04 October 2010 - 05:22 PM

View Poststickdog, on 04 October 2010 - 05:06 PM, said:

How do I do this when rendering a view rather than simply making a link?


It doesn't work that way i think

you render a view in your controller or render partially in your view but if you open a new page from your form that new page will be /controller/action and there you decide what view to render


example (very basic)

i go to /site/index
in my SiteController there is an actionIndex , which decides what view to render etc
let's take the index.php view to keep it easy

now if on that view i have a link to href=/site/otherpage with target="_BLANK" it will open a new tab/window (depends on the browsers settings)
on that moment we load SiteController -> actionOtherpage and there you decide again what view to render

try out the tutorials first, they are very helpfull. maybe read up how MCV works
(\ /)
( . .)
C('')('') -- This is Tiny Bunny. Copy Tiny Bunny into your signature to help him on his way to world domination.
Posted Image
0

#6 User is offline   stickdog 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 29-April 10

Posted 04 October 2010 - 05:39 PM

View PostMukke, on 04 October 2010 - 05:22 PM, said:

It doesn't work that way i think

you render a view in your controller or render partially in your view but if you open a new page from your form that new page will be /controller/action and there you decide what view to render


example (very basic)

i go to /site/index
in my SiteController there is an actionIndex , which decides what view to render etc
let's take the index.php view to keep it easy

now if on that view i have a link to href=/site/otherpage with target="_BLANK" it will open a new tab/window (depends on the browsers settings)
on that moment we load SiteController -> actionOtherpage and there you decide again what view to render

try out the tutorials first, they are very helpfull. maybe read up how MCV works


Look, I don't care how this works, and I realize that I am probably missing something very rudimentary. I just want this to work.

I want to collect information from the user using a form view, then when the submit button is hit, I want to generate a new browser tab that uses the information I collected on the form to generate some view output on a new browser tab. I can get this to work using the same browser tab. What do I have to do to render a view on a new browser tab?
0

#7 User is offline   Mukke 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 05-September 09
  • Location:Brussels (Belgium)

Posted 04 October 2010 - 06:07 PM

look i don't know why you are upset, i'm only truing to help, and making a new topic isn't really helping the cause either

but i would still do the same thing,

make the button click variable on what the browser inputs

the easiest way it probably with javascript

<script>
function redirect_to_newtab()
{
  window.open('/site/customlayout/id/'+$('userinput').value);
}
</script>
<form onSubmit="redirect_to_newtab(); false;">
<input type="text" id="userinput" />
</form>


ofc this is just to explain what i mean, i'm sure that if i took my time there are better ways to rewrite this, even better to go with the yii framework but that's basicly what you want
(\ /)
( . .)
C('')('') -- This is Tiny Bunny. Copy Tiny Bunny into your signature to help him on his way to world domination.
Posted Image
0

#8 User is offline   Lilt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 06-July 10

Posted 04 October 2010 - 06:13 PM

Okay, what you want is to use the target attribute of the form. Reading this page on w3schools is a good place to start. Assuming you're using a CActiveForm widget or similar, the way to set this attribute is using the htmlOptions property:
$form = $this->beginWidget('CActiveForm', array(
    'id'=>'...',
    'enableAjaxValidation'=>...,
    ...,
    'htmlOptions'=>array('target'=>'_blank'),
));

The last line there does what you are asking for.
0

#9 User is offline   Mukke 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 05-September 09
  • Location:Brussels (Belgium)

Posted 04 October 2010 - 06:23 PM

View PostLilt, on 04 October 2010 - 06:13 PM, said:

Okay, what you want is to use the target attribute of the form. Reading this page on w3schools is a good place to start. Assuming you're using a CActiveForm widget or similar, the way to set this attribute is using the htmlOptions property:
$form = $this->beginWidget('CActiveForm', array(
    'id'=>'...',
    'enableAjaxValidation'=>...,
    ...,
    'htmlOptions'=>array('target'=>'_blank'),
));

The last line there does what you are asking for.


Yeh that works too lol
(\ /)
( . .)
C('')('') -- This is Tiny Bunny. Copy Tiny Bunny into your signature to help him on his way to world domination.
Posted Image
0

#10 User is offline   stickdog 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 29-April 10

Posted 04 October 2010 - 06:56 PM

I'm very grateful for all the help here. I'm sorry if I sounded upset. Quite the contrary.

I may be a bit frustrated at myself because I don't understand some very basic things, but I am extremely grateful to everyone who has ever taken mercy on me enough to respond to my ignorant questions.

I will try this tomorrow and report back! Thanks!
0

#11 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,358
  • Joined: 12-October 09
  • Location:Croatia

Posted 05 October 2010 - 02:01 AM

View Poststickdog, on 04 October 2010 - 05:39 PM, said:

Look, I don't care how this works, and I realize that I am probably missing something very rudimentary. I just want this to work.


You have a big problem here (IMO), because if you don't care how it works you will not understand the answers you get here and you will not get it to work... people can just give you directions in solving the problem you have, but in the end, you are the one that has to do the coding and apply the solution you get here...

P.S. there is no need to open a new thread with the same question - http://www.yiiframew...iew-on-new-tab/
Find more about me.... btw. Do you know your WAN IP?
0

#12 User is offline   stickdog 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 29-April 10

Posted 18 October 2010 - 04:26 PM

View PostLilt, on 04 October 2010 - 06:13 PM, said:

Okay, what you want is to use the target attribute of the form. Reading this page on w3schools is a good place to start. Assuming you're using a CActiveForm widget or similar, the way to set this attribute is using the htmlOptions property:
$form = $this->beginWidget('CActiveForm', array(
    'id'=>'...',
    'enableAjaxValidation'=>...,
    ...,
    'htmlOptions'=>array('target'=>'_blank'),
));

The last line there does what you are asking for.


Sorry, I forgot to come back here before now. Thank you so much for this help!!!
0

#13 User is offline   stickdog 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 29-April 10

Posted 01 November 2010 - 10:47 PM

View PostLilt, on 04 October 2010 - 06:13 PM, said:

Okay, what you want is to use the target attribute of the form. Reading this page on w3schools is a good place to start. Assuming you're using a CActiveForm widget or similar, the way to set this attribute is using the htmlOptions property:
$form = $this->beginWidget('CActiveForm', array(
    'id'=>'...',
    'enableAjaxValidation'=>...,
    ...,
    'htmlOptions'=>array('target'=>'_blank'),
));

The last line there does what you are asking for.


OK, I thought that this had solved my problem, but this opens up a whole new set of problems instead. What I want to do is it render, not link, a view in its own window. I want to somehow to use my controller to open up a new target window in which to render a view if and only if the form validates after the select button is pushed.

When I use change the form to 'target'=>'_blank' I get a new tab/window every time the submit button is pushed whether or not the form validates. This is unacceptable. I only want to open a new tab/window when the form entries are valid.

I also continue to have a problem with my dependent drop down field whose selected values always disappear upon validation.

Does anyone have any advice for a truly desperate soul? I am so close to having this working, yet still so far.
0

#14 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 02 November 2010 - 05:12 AM

View Postmdomba, on 03 October 2010 - 05:32 AM, said:

To open a link in a new tab add
target="_blank"
to the link...

General comment / advise: No matter, what solution will be proposed to solve this problem, it is IMHO worth noting that at the very end it is browser, which decides how to handle target="_blank" attribute. Try to realize that it is browser not your webpage, which actually opens new tab or new window. And it is actually up to webbrowser developers not yourself to make 100% if that tab or window will be opened for you! This may lead into serious problems, if you design and develop your application with assumption that results of any operation will be displayed in new tab or window. And what, if not?

And there are at least rummors, if not confirmed information, that this attributte will shortly became deprecated - i.e. newest versions of webbrowsers will stop handling it! As global movement is toward idea that it is up to user not the browser or webpage creator to decide whether particular webpage should be displayed in the same or in a new window or browser tab.

Modern, professional webpages and browser utilizes this idea in manner that left-button-click in any link or button opens results always in the same window or tab while middle-button-click always opens it in new windows or tab. This way user decides and this is how it should always be IMHO. Try to understand that deciding for end user on if he or she want or doesen't want to see results in new window / tab or to dedide for him in any other matter may only force your users / customers to decide to look for a better website.

Therefore, conlusion is that profesional webdevelopers should not focus on how to force browser to open anything in new window or tab as this feature might be terminated permanently shortly. It would be better to focus on how to rewrite or redesign application for not using this feature at all. jQuery UI or any other JS framework modal dialogs / message boxes would be a good idea to look for. They work for sure and even look much better, because you can style them with CSS.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
1

#15 User is offline   chump9 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-January 14

Posted 14 January 2014 - 12:53 PM

View Poststickdog, on 01 November 2010 - 10:47 PM, said:

OK, I thought that this had solved my problem, but this opens up a whole new set of problems instead. What I want to do is it render, not link, a view in its own window. I want to somehow to use my controller to open up a new target window in which to render a view if and only if the form validates after the select button is pushed.

When I use change the form to 'target'=>'_blank' I get a new tab/window every time the submit button is pushed whether or not the form validates. This is unacceptable. I only want to open a new tab/window when the form entries are valid.

I also continue to have a problem with my dependent drop down field whose selected values always disappear upon validation.

Does anyone have any advice for a truly desperate soul? I am so close to having this working, yet still so far.


Hi all. I'm new here. (nice to meet you!)
I read all the thread hoping that in the end (or on the way) there will be a solution, because I have the same problem, but the question stayed without answer.
my problem is that:
The webpage needs to check the form with the server, and in case that everything is alright it gets a url address from the server and opens it in a new tab. the url is for paying in paypal.
SO - anybody can help?
tnx
Gil
0

#16 User is offline   uEhlO4a 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 05-January 14
  • Location:Ukraine, Kiyv

Posted 14 January 2014 - 02:57 PM

if you use raw HTML your code may look like

// views/your-form.php

<form id="form1">
<input name="var1" id="var1" />
<input type="submit" />
</form>

<script>
jQuery('#form1').on('submit', function(e){
  e.preventDefault();
  
  jQuery.post('your/url/here', {your_var_name: jQuery('#var1').val()}, function(data){
     //data is object with result attribute, for example
      if(data !== 'undefined' && data.result) {
          window.open('your/url/to/open', 'windows title');
      }
  }, 'json');
});
</script>


//controllers/your_controller.php
...
function actionYourAction() {
   if (Yii::app()->request->isAjaxRequest) {
      //check your stuff here
      // and response 
      $r = new stdClass();
      $r-> result = true;
      echo echo CJavaScript::jsonEncode($r);
   }
}

0

#17 User is offline   chump9 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-January 14

Posted 15 January 2014 - 09:08 AM

View PostuEhlO4a, on 14 January 2014 - 02:57 PM, said:

if you use raw HTML your code may look like

// views/your-form.php

<form id="form1">
<input name="var1" id="var1" />
<input type="submit" />
</form>

<script>
jQuery('#form1').on('submit', function(e){
  e.preventDefault();
  
  jQuery.post('your/url/here', {your_var_name: jQuery('#var1').val()}, function(data){
     //data is object with result attribute, for example
      if(data !== 'undefined' && data.result) {
          window.open('your/url/to/open', 'windows title');
      }
  }, 'json');
});
</script>


//controllers/your_controller.php
...
function actionYourAction() {
   if (Yii::app()->request->isAjaxRequest) {
      //check your stuff here
      // and response 
      $r = new stdClass();
      $r-> result = true;
      echo echo CJavaScript::jsonEncode($r);
   }
}



Thank you for your response.
The problem was that each time I checked it the chrome treated it as a popup, and I thought that every use of window.open in js will cause the browser to behave like that. maybe it was because I checked it in debugging mode, or other circumstances that could made it.
Thanks again and good luck!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users