Fixing URl form issues -- Or just plain get the real URL

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
JeremyBASS

Fixing URl form issues -- Or just plain get the real URL

Post by JeremyBASS »

Hello, I helped a few people out over the last month with this one item, "why does my * form not work/post/submit" at work?? Well to be honest... the reason seems to vary and I'm not best to they you why ... but this is what I can tell you, what to do about it.

There are a few ways to solve the form issue which even work on many other form based module issues.  So let's take them one at a time... first you need to look at all logs and inspect the code.  What I look for is what the action="" is for the form... most of the time it's the url in there that is part of the issue so let’s just replace it. 

There are two ways to handle this:
1.) Try replacing the action for just index.php
2.) Replace it with the proper URL of the page your on
    i.e. you’ve rendered a mod that sits inline on a page and looks like it's moving but it's still on the same page alias which is not the proper URL**

I find 9 times out of 10 just the index.php fix works on the first try but only the second works for the inline mods... so let's do it...


1.)

Code: Select all


{$startform|regex_replace:"/action\s*=\s*\"[^\"]*\"/":"action=\"index.php\""}

or

{$form_start|regex_replace:"/action\s*=\s*\"[^\"]*\"/":"action=\"index.php\""}


2.)URLhere UDT

Code: Select all


/////// real url

global $gCms;
$urlBASE = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER["QUERY_STRING"]))
$urlBASE .= "?".$_SERVER['QUERY_STRING'];
if (isset($gCms->config['assume_mod_rewrite']) && ($gCms->config['assume_mod_rewrite']==true)) {
 
$urls = str_replace("index.php?page=", "", $urlBASE);
$urls = str_replace("index.php", "", $urls);
 
}else{
 
$urls = $urlBASE;
 
}
echo $urls;

and

Code: Select all

{capture assgin=newURL}{URLhere}{/capture}



{$startform|regex_replace:"/action\s*=\s*\"[^\"]*\"/":"action=\"$newURL\""}
or
{$form_start|regex_replace:"/action\s*=\s*\"[^\"]*\"/":"action=\"$newURL\""}




What this is aiming at doing is to bypass part without changing the file codes so if you need to upgrade or move server (which may fix the issue) you don't end up breaking something … plus your not locked down so you can’t move your pages...

Hope this helps or save you a little time...
Cheers
jeremyBass




*note that the URLhere UDT is a great way to pass a return url too...

Tested on 1.5.4 and below
Pretty URL friendly


**
Please advise if corrections to this are needed

Code: Select all

//// page url

global $gCms;
if ($gCms->variables['page_name'] !='') {
	$manager =& $gCms->GetHierarchyManager();
	$node =& $manager->sureGetNodeByAlias($gCms->variables['page_id']);
	
	$content =& $node->GetContent();
	if (isset($content) && is_object($content))
	{
		if ($content->GetURL() != '')
		{
		echo $content->GetURL();
		}
	}
}
/////// real url
$urlBASE = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER["QUERY_STRING"]))
$urlBASE .= "?".$_SERVER['QUERY_STRING'];
if (isset($gCms->config['assume_mod_rewrite']) && ($gCms->config['assume_mod_rewrite']==true)) {
 
$urls = str_replace("index.php?page=", "", $urlBASE);
$urls = str_replace("index.php", "", $urls);
 
}else{
 
$urls = $urlBASE;
 
}
echo $urls;

***********edit

I suppose smarty assign would be better... depends on what you need...

$gCms->smarty->assign('urls', $urls);
Last edited by JeremyBASS on Thu May 21, 2009 11:35 pm, edited 1 time in total.
Post Reply

Return to “Tips and Tricks”