Page 1 of 1

[SOLVED] Form in Fancybox IFrame

Posted: Sun Sep 16, 2012 1:58 pm
by nervino
Hi, I put a cmsms module page in a Fancybox iframe, in this way:

In the template.tpl of action.default.php:

Code: Select all

$(document).ready(function() {
        $("#create-user" ).fancybox({
        	'title': 'User',
        	 'titlePosition'    : 'outside',
            'width'             : 600,
            'height'            : 600,
            'modal'     		: 'true',

            'type'              : 'iframe',
            'href'              : "{/literal}{root_url}{literal}/modules/mymodule/action.create_user.php"
        });
    });
In action.create_user.php, I create the form, input fields etc. using cmsms functions
( like: CreateFrontendFormStart($id,$returnid,'create_user') etc. )
and I display them in action.create_user.php's template (".tpl").

All works fine, but when I submit the form (which is in the iframe and, on my thought, would call back action.create_user.php and show the result in the iframe) I have this error:
Not Found
The requested URL /modules/mymodule/moduleinterface.php was not found on this server.
Why the form isn't submitted to action.create_user.php?

Thanks

Re: Form in Fancybox IFrame

Posted: Sun Sep 16, 2012 2:21 pm
by calguy1000
CMSMS actions cannot be called directly in this way... that's a serious security issue, and numerous internal variables are not setup properly for the creation of forms, links etc.

You need to create a URL to an action using the create_url method... then use that in your javascript/fancybox. You should also add the showtemplate=false parameter to the URL so that only the {content} are of the page template (and therefore your form) are returned.

The form generated when fancybox reads the page should work properly then.

Re: Form in Fancybox IFrame

Posted: Sun Sep 16, 2012 5:52 pm
by nervino
Thank you, I'll try your suggestion asap.

I'd like to learn why that way of call an action page is a security issue, and which is the difference with the usage of the create_url method.
If you have time to answer i'll be glad.

Thanks again.

Re: Form in Fancybox IFrame

Posted: Mon Sep 17, 2012 3:34 pm
by nervino
I used "create_url" and it works perfectly with Fancybox iframe.

I also tried to use it in an ajax call within the template of the page displayed in the iframe, but I always got the JSON error:
SyntaxError: JSON.parse: unexpected character
I can't guess what the error depends on. To debug it, I put only

Code: Select all

echo "bye bye";
in the cmsms action page called by ajax ({$url_ajax}).

What am I doing wrong?

This is the jquery ajax code I'm using:

Code: Select all

$(document).ready(function(){
	
	$("select#users").change(function() {
		  $('#loading').addClass('wait');
		  var user_code = $("select#users").val();
								  $.ajax({
									   type: "POST",
									 url: "{/literal}{$url_ajax}{literal}",
									 
									 dataType : 'json',
									   data: {
											  user_code: user_code
											  },
										  success : function(data)
										  {
											  $('#loading').removeClass('wait');
											  if (data.error === true)
											  {
												  alert(data.error);
											  }
											  else if (data.error === false)
											  {
												 $('select#props').html(data.props_list).text();
											  }
										  },// END SUCCESS
									  
										  error : function(XMLHttpRequest, textStatus, errorThrown)
										  {
											  alert(errorThrown);
											  
										  } // END ERROR
										  
									  });// END AJAX POST
	  }); 

}) // END jQuery(document).ready(function($)

Re: Form in Fancybox IFrame

Posted: Mon Sep 17, 2012 4:46 pm
by calguy1000

Code: Select all

url: "{/literal}{$url_ajax}{literal}+'&showtemplate=false",
Try that.

Re: Form in Fancybox IFrame

Posted: Mon Sep 17, 2012 8:14 pm
by nervino
Perfect!

I was adding the "showtemplate=false" parameter in this way, but didn't work:

Code: Select all

$pars = array('showtemplate'=>'false');
$smarty->assign('url_ajax', $this->create_url($id, 'ajax_u', $returnid, $pars ));
Thanks a lot!