Why does HttpHeader X-Original-URL not exist on some pages? - coldfusion

My site using URL Rewrite to make SEO friendly URLs. This makes self-posting a form back to the same page a little tricky.
However in ColdFusion I do this for the form's action attribute:
<form name="formSortBy" method="post" enctype="multipart/form-data" action="#StructFind(GetHttpRequestData().headers, 'X-Original-URL')#">
</form>
The important part here is the #StructFind(GetHttpRequestData().headers, 'X-Original-URL')# which gets me the URL of the page.
However the X-Original-URL key just doesn't exist on some pages so I get an error from ColdFusion saying:
Cannot find X-Original-URL key in structure.
The specified key, X-Original-URL, does not exist in the structure.
This is happening when I click to go to the homepage of a section I am in.
So X-Original-URL exists if I go to http://www.sitename.com/products/gaming but it won't exist if I go just to http://www.sitename.com/products
Is there anyway to get around this or make it work like I need it to?

Sounds like there is an issue between your rewrite rules and CF.
But, there is an easy fix - you can get a form to post to itself by simply not specifying the action attribute.

Related

How to make input box work in the result page

I am learning Django and i learn on making small project for lEARNING PURPOSE.
I learned how work with input and use as variable. Now i want to use search box with the same principle.
Please see the link of input based :
https://stackoverflow.com/questions/58813945/changing-form-to-search-box
index.html is the input after inserting info and clicking ok it directs to index2.html which shows the results
What I need to change besides POST to GET to make it work as it works with input function? do i need to change form, models?
My concern also i want to inset search bar in the navigation in index2.html where user can make search from the result page. This is my index2.html page. I tried to put {{form.as_p }} inside the form function but it does not work. I want after putting infro in search box and clicking search glyphicon (which does not work) will stay on the same page index2.html
I searched the internet and read stackoverflow other examples, but they use complicated version, i need a simple one :
1. i want to have search box on index.html page so it does not show me the name in front of input box and
2. i want search box in the index2.html page keep implementing the same function as index.html so a user do not have to go the initial page to search new data.
Any help or tips would be highly appreciated.
Since you're using bootstrap4 I would recommend to use its template tags and form field customization options.
Example:
{% bootstrap_field form.login show_label=False addon_before='<span class="fa fa-user"></span>' %}
Not: this example uses Font Aweseome for icons.
Also you're not using the real power of Django Bootstrap4, see Quickstart. You can always override the version of Booststrap or the CDN used in your settings.py if needed: Settings.

After saving in a form i want it to point to another site not the forms list

It's probably a stupid question.
I have a form on a custom list that I hade to custom design (the form for editing). But because of the law (GDPR) I can't let the users see the list after they save the form.
One part is sloved by them entering in the form from a page with a direct link to it. But the relinking is not.
This is the original part that I figured I have to change
<SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton2"/>
I changed It to this
<SharePoint:SaveButton RedirectUrl="http://www.google.com" runat="server" ControlMode="New" id="savebutton2"/>
This also hellped but It just retuns me to the same empty form.
Can you tell me what I have to change to get it to actualy link it to the redirect link?
As I understand your question, you want to redirect users to another site after they've submitted a form.
What I have done in the past is modify the URL of the new form so that instead of the new item url being : http://mysite/org/hr/Lists/Exit/Item/newifs.aspx?List=b5b9e317%2D4366%2D4557%2D8d29%2Db5dedc71a75a&Source=http%3A%2F%2Fmysite%2Forg%2Fhr%2FLists%2FExit%2FCompleted%2Easpx&RootFolder=&Web=a86f3198%2D79a6%2D4e7f%2Daa26%2D448559533df8
I change the address after &Source in the above URL to the other site. So, it would now look like this:
http://mysite/org/hr/Lists/Exit/Item/newifs.aspx?List=b5b9e317%2D4366%2D4557%2D8d29%2Db5dedc71a75a&Source=http://www.google.com
What will happen, form will open, they'll save, and once the form closes, it will direct them to Google. I didn't need to modify the OOB save buttons - it's a good deal cleaner and quicker!
Hope this helps.

Django links on base template

Django 1.5.1
Experience, getting started
I'm currently working on my static side of the site.
And creating the HTML/CSS/JS stuff. In the base html i have some links.
One of them is "about" that will lead to the ...:8000/about
Now when im on the about page there are the same links cause they are in the base template.
When i click on them now i get ...:8000/about/about
and it will go on adding the /about each time i click.
How should i get this link to always point to ...:8000/about
Thank you.
Absolute URLs.. start your links with /
<a href="/about/"> instead of <a href="about/">
Also, if it will "add /about" each time you click, that means you're re-rendering your view... which means your URLConf probably has a too-broad regex (make sure your line is terminated by a /$
Kind of sounds like you have a line like url(r'^about/', 'foo') where /about/about/about will continue to match.
It's also best practice to use the {% url %} tag via named urls. Sooner or later you'll change a URL and thank everyone for it.
https://docs.djangoproject.com/en/dev/topics/http/urls/#named-groups

Connecting two views in Django

I want to make sure that my visitors (not authenticated users), are unable to visit a particular view without coming directly from a "previous view". I've kind of had to manually create a form preview and confirmation state. It's the step between submission and preview, and preview and confirm I'd like to "secure".
form submission-view -> preview-view -> confirm-view.
Is there some way that I can create a unique hash, POST it, and check if it's correct, or somewhat generate a cookie, session — or anything else that feels clever?
I'm a Django beginner (programming beginner in general) and any snippets' or pointing me in a right direction would be very much appreciated!
Thanks.
There are at least two ways you can accomplish this that I can think of:
One would be to include a hidden field in your form or querystring value that contains your hash/unique that you want to pick up in the next view. If it's not there, or incorrect, redirect.
Another would be to check the referring url from the request.META to see if they've come from the view you want them to come in on first, and save a session value from the form submission to carry through the rest of the views. If it's not there, redirect. If the referring URL isn't what you expect, redirect.
Whether you use a cookie, session, querystring parameter or hidden form post, it's all doing the same thing - validating a value exists. Whatever method works best, is what makes the most sense for you as the developer and most likely maintainer of said app.

Django app links lose domain in Internet Explorer

I have a Django-powered page running on Apache with mod_wsgi. It works just fine in Firefox. When I switch to Internet Explorer, however, none of my links work. They all drop the domain part of the link.
For example, in Firefox, if I mouse over one of my links, I see something like this:
http://mydomain.edu/pathtomystuff/linkpage/
and it works.
However, in Internet Explorer, the same link shows this when I mouse over it:
http:///pathtomystuff/linkpage/
and obviously doesn't work.
If I manually type the address in Internet Explorer, it works fine. It's just the links.
This is probably something obvious and boneheaded. Please forgive me :)
UPDATE
Well I did figure out something of a "solution". I had BASE href= {{request.path}} in my base html file (which all other pages in my site extend). In reviewing the source code shown by IE and Firefox, both were seeing BASE href= which means request.path was not being passed to my template. So I changed it to BASE href=mydomain.edu and it works in IE now.
This is not a great fix though because it takes away from the portability of the django app...
If you want to preserve portability (as well as maintainability), the easiest and most "djangonistic" way to proceed would be to use {% url %} tags in your templates.
Note that the {% url %} tag should be passed a view as 'argument', for example: {% url myApp.views.myView foo='bar' %} will use your urlconf to create the appropriate url that will point to the myApp view called myView, with the value 'bar' passed as the 'foo' arg.
Of course, you needn't have arguments in all your views, the foo='bar' part is purely optional (Please do note that you shouldn't specify the request argument)
The most common use would be to use a syntax such as:
MyLink
Basically what you're trying to do here is reinvent the url tag, it already exists, so use it! :)