[SOLVED] Form in Fancybox IFrame

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Locked
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

[SOLVED] Form in Fancybox IFrame

Post 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
Last edited by nervino on Mon Sep 17, 2012 8:14 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Form in Fancybox IFrame

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Form in Fancybox IFrame

Post 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.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Form in Fancybox IFrame

Post 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($)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Form in Fancybox IFrame

Post by calguy1000 »

Code: Select all

url: "{/literal}{$url_ajax}{literal}+'&showtemplate=false",
Try that.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Form in Fancybox IFrame

Post 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!
Locked

Return to “Developers Discussion”