No need of CGI.script_name - coldfusion

Please refer to the following code:
<cfform method="POST" action="#CGI.script_name#">
<p>Enter your Name:
<input name="name" type="text" hspace="30" maxlength="30">
<input type="Submit" name="submit" value="OK">
</cfform>
<cfscript>
function HelloFriend(Name) {
if (Name is "") WriteOutput("You forgot your name!");
else WriteOutput("Hello " & name &"!");
return "";
}
if (IsDefined("Form.submit")) HelloFriend(Form.name);
</cfscript>
Source: http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=UDFs_01.html#1167055
The code runs fine even without CGI.script_name attribute of action field. May I know why it's required then? The description says "Uses the script_name CGI variable to post to this page without specifying a URL. "

The default action of an HTML form is to submit to itself when no action is specified. See this related discussion on the topic: Is it a good practice to use an empty URL for a HTML form's action attribute? (action="")
I always include an action, if for no other reason, to avoid confusion.

Related

coldfusion cffile upload replace no file selected

In Coldfusion, using cffile upload, when a file is selected with the browse button the name of the selected file shows next to the button. So far, so good. When I submit the file for upload, the text changes back to "no file selected". This is doubtless because we are submitting a form.
However, I'm submitting the form to the same page, and would like to see the name of the file selected instead of "no file selected" which is likely to confuse the user.
The code:
<form
enctype="multipart/form-data"
method ="post"
name ="attupload"
action ="">
<cfoutput>
<table style = "margin-left: 40%">
<tr><td>
<input name="theupload"
type="file"
style = "font-family: comic sans ms;
color: ##679C9C">
</td></tr>
</table>
<div style = "width:20%; margin:5% auto 5% 45%">
<input name = "submit"
type = "submit"
class = "submitbut"
style = "font-size: 16px"
value = "Upload File">
</div>
</cfoutput>
</form>
The words 'no file selected' seem to be part of the input name = 'upload' field, but ColdFusion evidently takes control of it, and I cannot insert anything else.
Does anyone know how I can control the 'no file selected' note, so that I can put the name of the selected file back in that spot? I have tried with javascript, but it is simply ignored.
Once a file has been selected, you can access its properties via JavaScript with the File API. You can't affect the value displayed next to the default <input type="file"> field with JavaScript.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file
You should also avoid submitting forms to the same page. You should follow the process:
Form page
HTTP POST to form processing page.
after form processing, <cflocation> (301 redirect) back to a list page or the form page.
When you post to the same page, the user can hit reload and be prompted to resubmit form data. This can be problematic in many situations. As an alternate, you can post the form data using Ajax or better, via Fetch. This avoids a re-post on page reload and redirecting away from the current screen.
Also, you should avoid naming an <input type="submit"> "submit". It can conflict with the JavaScript function submit() should you need to use it.
<input name = "submit"
type = "submit"
class = "submitbut"
style = "font-size: 16px"
value = "Upload File">

Need help getting DPM to work

First off, I am using DPM because my understanding is that Accept.js does not support e-check and the whole reason that I am involved in making this update is to add e-check support.
I am trying to rewrite a classic ASP page for DPM in VB.Net using razor syntax. I have repeatedly received the error response:
The following errors have occurred.
(13) The merchant login ID or password is invalid or the account is inactive.
I know the default response. I am using the wrong login in or posting to the wrong URL. I am posting using the same URL that my current ASP page is posting to and I am using the same x_login value.
Also, if I go to this URL:
https://secure.authorize.net/gateway/transact.dll?x_version=3.1&x_type=AUTH_ONLY&x_amount=1.99&x_car... it returns that the credit card has expired. If I enter an invalid x_login on that url it returns "The merchant login ID or password is invalid or the account is inactive." If I enter my valid x_login and an invalid x_tran_key I receive "This transaction cannot be accepted."
So, I know that my x_login is correct and that I am posting to the correct URL.
In order to eliminate any coding issues, I put together a simple form just to post static information to the URL:
<html>
<body>
<form method="POST" action="https://secure.authorize.net/gateway/transact.dll">
<input type=hidden id="x_login" name="x_login" value='MY_LOGIN'/>
<input type=hidden id="x_cust_id" name="x_cust_id" value='106400289'/>
<input type=hidden id="x_card_num" name="x_card_num" value='5424000000000015'/>
<input type=hidden id="x_exp_date" name="x_exp_date" value='12-17'/>
<input type=hidden id="x_card_code" name="x_card_code" value='123'/>
<input type=hidden id="x_fp_hash" name="x_fp_hash" value='84EFB49E5F4A8F7CB3EEB3C6A1B2B305'/>
<input type=hidden id="x_amount" name="x_amount" value='123.60'/>
<input type=hidden id="x_fp_timestamp" name="x_fp_timestamp" value='1493038728'/>
<input type=hidden id="x_fp_sequence" name="x_fp_sequence" value='531'/>
<input type=hidden id="x_relay_url" name="x_relay_url" value='https://www.my.com/CCPayment2.vbhtml'/>
<input type=hidden id="x_relay_response" name="x_relay_response" value='Y'/>
<input type=hidden id="x_type" name="x_type" value='AUTH_CAPTURE'/>
<input type=hidden id="x_currency_code" name="x_currency_code" value='USD'/>
<input type=hidden id="x_version" name="x_version" value='3.1'/>
<input type=hidden id="x_invoice_num" name="x_invoice_num" value='2'/>
<input type="submit"/>
</form>
</body>
</html>
I verified that my hash value was correct using the link at:
http://developer.authorize.net/api/reference/responseCode99.html
This returns the error message:
(13) The merchant login ID or password is invalid or the account is inactive.
In researching I did find where one developer received that message because he used the same test card and amount and evidently that message is returned as the result of a duplicate. So I changed the amount, the card, the time stapm, and the hash and tried again with the same result. I also used both the "name" and "id" within the hidden fields since I have seen references to both of those.
I would appreciate any help that anyone can provide.
In case anyone else is looking for an answer to this in the future, the message:
(13) The merchant login ID or password is invalid or the account is inactive.
evidently appears for more reasons than supplying the wrong login id or connecting to the wrong url at least as far as DPM is concerned.
In my instance, the refresh on my link "https://www.my.com/CCPayment2.vbhtml" contained an invalid URL. Once I discovered and fixed this, everything worked fine.

How do I pass multiple variables from one handler to another in GAE?

I want to redirect users to a confirmation page that will display both subject and content (if there is any) if they enter a valid subject, but stay on the same page and display an error if the subject is either blank or over three hundred characters.
Here is my backend code:
def post(self):
subject = self.request.get('subject')
content = self.request.get('content')
a, b = self.validSubject(subject)
if a == True and b == True:
self.redirect('/confirm')
else:
if a == False:
error = "Title cannot be blank!"
if b == False:
error = "Title cannot be over 300 characters."
self.render("newpost.html", subject = subject, content = content, error = error)
Here is the code for the newpost.html template:
<h2>New Question</h2>
<hr>
<form method="post">
<label>
<div>Title</div>
<input type="text" id="subject" name="subject">
</label>
<label>
<div>
<textarea name="content" id="postcontent"></textarea>
</div>
</label>
<b><div class="error">{{error}}</div></b>
<input type="submit">
</form>
I've tried adding action="/confirm" to the POST form, but that redirects to /confirm even if there is an error. I've looked at the webapp2 documentation but couldn't find anything on how to pass variables on a redirect. (https://webapp-improved.appspot.com/api/webapp2.html#webapp2.redirect)
I'm using webapp2 and jinja2. Thanks for any help in advance, I've been looking at this piece of code for quite a while :(
The pattern you're trying to write doesn't work within http, irrespective of what backend platform or language you're using. Your HTML is posting to the server and the GAE code is handling the post. At that point in the interaction, the browser has already submitted and is awaiting a response from the server. You can't stop the submission at that point since it's already happened.
You should consider validating the input in Javascript before the form is even submitted to the server. That way you can suppress the submission of the form in the first place if your data isn't valid.
Take a look at the following question to see an example of this:
JavaScript code to stop form submission

Django Form Field Problems with Cloudinary's CloudinaryImage Class

I've got a Django form that is displaying a ClearableFileInput for a CloudinaryImage (from Cloudinary). Things are working great, except when I display the form field, I get a mangled href in the anchor element:
Currently: <cloudinary.CloudinaryImage object at 0x10b3f4ad0> <input type="checkbox" name="logo-clear" id="logo-clear_id" /> <label for="logo-clear_id">Clear</label><br />Change: <input id="id_logo" type="file" name="logo" class="span4" />
Here is the template code I am using:
<div class="fieldWrapper">
<label for="id_logo"><h3>{{ form.logo.label }}:</h3></label>
{{ form.logo|add_class:"span4" }}
<p>{{ form.logo.help_text }}</p>
</div>
The add_class part come from django-widget-tweaks. I've taken the add_class part out with no change in the output.
Here is my form definition:
class OrganizationFormTheme(forms.ModelForm):
pass
class Meta:
fields = ('logo',)
model = Organization
It looks like Django is having problems with the CloudinaryImage's url function. I suspect it is looking for a simple property rather than a function.
Any suggestions on how to handle this? Should I subclass CloudinaryImage and rewrite the url function somehow?
Indeed there was a conflict between the url function and the url property.
We've changed the function to be build_url instead of url.
In addition, you can specify transformation parameters as the url_options parameter when calling the constructor of CloudinaryImage. Then you can use the url property for getting the full Cloudinary URL.
The fix is available in the latest release of the Python library: http://pypi.python.org/pypi/cloudinary

ColdFusion variable not set properly

I have a form with some html elements. It has a check box which is by default checked. On click of the submit button it calls the submitForm function
Based on the checkbox condition it has to do the action. If the checkbox is Y, then it has to do one form action and if not checked then another action. Using javascript I have checked whether its checked or not. But I am not able to set the coldfusion variable for this. Always it overwrites the variable.
Below is the code snippet
This is the ColdFusion variable which is used. This is by default set to Y
<cfset form_condn_var = 'Y'/>
function submitForm(){
if (document.getElementById('Show_Final_Model').checked)
{
form.Show_Final_Model.value = 'Y';
}
else{
<cfset form_condn_var = 'N'/>
}
}
<cfif '<cfoutput>#form_condn_var#</cfoutput>' eq 'Y'>
<form id="form1" action="test.cfm" method="POST" target="testmain">
<cfelse>
<form id="form1" action="<cfoutput>#something#</cfoutput>" method="POST" target="_blank" onSubmit="">
</cfif>
It always set the variable form_condn_var as N and it goes to the else condition of the form irrespective of the condition. . But when I alert the value its comes correctly.
I cannot use hidden variable also as the form is not being called initially. Based on the checked condition only it is accessed.
Could somebody please tell me why the form_condn_var gets overwritten irrespective of the condition being checked.
Or is there any other way I can achieve this?
Thanks in advance
Short version
If I have understood your logic correctly then you can replace all of what you pasted with the following <cfif>
<cfif IsDefined('form.Show_Final_Model') AND form.Show_Final_Model EQ 'Y'>
<form id="form1" action="test.cfm" method="POST" target="testmain">
<cfelse>
<form id="form1" action="<cfoutput>#something#</cfoutput>" method="POST" target="_blank" onSubmit="">
</cfif>
Explanation
Your main problem here is that you have got Javascript outside of tags with a coldfusion within them and seem to be confusing what each language does.
First of all Coldfusion renders the HTML. As far as Coldfusion is concerned, the javascript if statement is just text, and so it sees the following logic
<cfset form_condn_var = 'Y'>
<cfset form_condn_var = 'N'>
<cfif form_condn_var EQ 'Y'> <!--- form_condn_var === '<cfoutput>#form_condn_var#</cfoutput>' but much cleaner --->
.......
<cfelse>
.......
</cfif>
In turn leading to the following HTML being rendered
function submitForm(){
if (document.getElementById('Show_Final_Model').checked)
{
form.Show_Final_Model.value = 'Y';
}
else{
}
}
<form id="form1" action="<cfoutput>#something#</cfoutput>" method="POST" target="_blank" onSubmit="">
I suspect in your example you trimmed out some logic though as otherwise that Javascript would be output as plaintext, as it is not within <script> tags.
If you are submitting your checkbox and then setting the form action for the next form (form 2 - after you've chosen the checkbox) I think what you want to do is the following:
<cfparam name="form.Show_Final_Model" default="N"/>
<cfif form.Show_Final_Model IS 'Y'>
<form id="form1" action="test.cfm" method="POST" target="testmain">
<cfelse>
<form id="form1" action="<cfoutput>#something#</cfoutput>"
method="POST" target="_blank" onSubmit="">
</cfif>
This would be on the handler page (after the form is submitted). You would not need the JS function.
If however you are trying to change the action param of your form to something else based on the check or uncheck of the checkbox (in other words - withing the same form) then ALL of your code needs to be javascript and CF has little to do with it. Set 2 variables - action a and action b, check the value of the checked form element and change the form.action value to whichever one you want.
But most importantly get settled in your mind on what is "server side" and what is "client side" .. that's where you are slipping up. good luck :)
I'm not sure if I'm understanding the question correctly, but it would seem that this situation could be handled purely on the action page based on conditional processing based on the result of the form checkbox value. Instead of sending the form to two different action templates based on the value of the checkbox, just process the form accordingly on the action template based on conditional processing of the checkbox form value.