ColdFusion submitting a form - forms

I have a form where an user can add new people to the list. I need it to only allow the form to update if the required fields are filled out.
My current code works in Chrome or FireFox, but not with with Safari. In Chrome and FireFox, it will not submit the form unless the fields are filled out. However, Safari allows the user to submit the form even if it is left blank.
Is there any other way to write the code to make it work with all three browsers? Below is just a little of the code for some of the required fields.
<cfform method="post" action="##" name="aForm" id="addClientForm" class="">
<input type="hidden" name="method" value="clientAdd">
<input type="hidden" name="datasource" value="<cfoutput>#request.dsn#</cfoutput>">
<input type="hidden" name="Active" value="1">
<div style="float:left;" class="formContent470">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<th colspan="" style="text-align:left;">Add Client</th>
</tr>
<tr><cfoutput>
<td>
Contact
<span style="color:red">*</span>
<input type="Text" name="Contact" value="" required="Yes" message="Contact is required" maxLength="75" class="inputText430">
</td>
</tr>
<tr>
<td>
Client Name
<span style="color:red">*</span>
<input type="Text" name="ClientName" value="" required="Yes" message="Client Name is required" maxlength="75" class="inputText430">
</td>
</tr>
<tr>
<td>

Sounds to me like you're looking for server side validation. I would, of course, validate client side using Javascript and THEN back that up with server side.
Despite the well meaning advice avoid CFINPUT and CFFORM if you can (My opinion others may differ). You'll gain far greater flexibility/portability using a client side library like JQuery and sticking with plain Jane HTML form fields (steps off podium).
That being said, and assuming you'll stick with server side validation as a starting point, there's an "old school" CF method of form validation using hidden fields with specially formed name attributes. That should solve your problem. You can see this method described very well in the documentation.
-Cheers!

Related

Custom Paypal form only collecting some data after completed transaction

I have created a custom form following information I have gained from the Paypal KB, StackOverflow and other support forums. However things are not working as I had planned. I'm guessing I've missed something along the way that's causing my issue.
I have created a custom donation button building the base of what I need in Paypal, but then not saving the button, and using the code Paypal generates as the base which I then customize (code posted below). The point is to collect info of the type of donation (dropdown), name of the person the donation is honoring (text field), the amount the donation is for (amount field) and then 5 other optional text fields using the on and os variables. At the end of all fields is the Paypal donate button.
What happens correctly:
When someone fills out the form and then clicks donate ALL values they enter into the form show up properly on the PayPal payment page.
When the transaction is complete the DONOR gets an email showing their transaction AND shows all the information from the form they filled out in the donation details area. Everything on the donor side goes perfectly and they never know there is a problem.
What goes wrong: HOWEVER, things go awry for the organization accepting the donation at payment completion. When the organization gets the email notification of the payment only the top 3 values from the donation form show in the details (value from the dropdown menu, the value in the first text field, and the amount field). All other relevant paypal transaction info is there and the transaction is fine. But all the needed detail that was collected from the custom form is missing. If I log into the paypal account that received the payment I see the transaction, but just as the notification email all data after the amount is missing.
Summary:
The custom form, for the donor, appears to function properly including values passed from the web form to the paypal payment form and even included in the donation receipt email received by the donor. However, when it comes to the organization only the first 3 fields show in the notification email and on the transaction itself in the paypal account
Any idea why all values show up on the donor email notification and only 3 values show up on the organization site? Has my formatting of the form (adding spaces between fields) broken the form? If so why does all info show properly for the donor and not the organization? I have included the form code below. Please advise. Thank you so much!
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"><input type="hidden" name="cmd" value="_donations"> <input type="hidden" name="business" value="paypal#sthecompany.org"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="item_name" value="Honor/Memorial Donation"> <input type="hidden" name="button_subtype" value="services"> <input type="hidden" name="no_note" value="0"> <input type="hidden" name="cn" value="Please add your comments here"> <input type="hidden" name="no_shipping" value="2"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted">
<table>
<tbody>
<tr><td><input type="hidden" name="on0" value="Gift Type">Gift Type</td></tr>
<tr>
<td height="32"><select name="os0">
<option value="Honor">Honor</option>
<option value="Memorial">Memorial</option>
</select></td>
</tr>
<tr>
<td><input type="hidden" name="on1" value="Name">In Honor or Memory of</td>
</tr>
<tr>
<td><input type="text" name="os1" maxlength="200"></td>
</tr>
<tr>
<td><label for="amount">Amount $<br /></label><input id="amount" type="text" name="amount" value=""></td>
</tr>
<tr>
<td><br />If you would like a letter sent to the honoree or next of kin,<br />please fill out the following information otherwise leave blank. <br /><br /> <input type="hidden" name="on2" value="Notification Name">Notification Name</td>
</tr>
<tr>
<td><input type="text" name="os2" maxlength="200"></td>
</tr>
<tr>
<td><br /><input type="hidden" name="on3" value="Notification Address">Notification Address</td>
</tr>
<tr>
<td><textarea name="os3" rows="5" cols="40"></textarea></td>
</tr>
<tr>
<td><br /><input type="hidden" name="on4" value="Notification City">Notification City</td>
</tr>
<tr>
<td><input type="text" name="os4" maxlength="200"></td>
</tr>
<tr>
<td><br /><input type="hidden" name="on5" value="Notification State">Notification State</td>
</tr>
<tr>
<td><input type="text" name="os5" maxlength="200"></td>
</tr>
<tr>
<td><br /><input type="hidden" name="on6" value="Notification Zip">Notification Zip</td>
</tr>
<tr>
<td><input type="text" name="os6" maxlength="200"></td>
</tr>
</tbody>
</table>
<br /> <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted"> <input type="image" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" alt="PayPal - The safer, easier way to pay online!"><img src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" alt="" width="1" height="1"></form>
I was able to produce the same results that you describe. I would suggest opening up a ticket with PayPal's Merchant Technical Team at www.paypal.com/mts. Once you have a ticket opened up, if you would like to provide the ticket number I will grab your ticket and look into this further. It may be a bug or intended, I would have to look deeper into the code. Intially some of the additional variables were not supported for some buttons, but I will look into it further and update you through your ticket as to if this is a bug or something that needs to have a feature request filed for.
I haven't checked whether those custom values are sent through an IPN message, but that might solve the problem.

Internet Explorer form submit with target to iframe not working

I'm using the hidden iframe method of submitting files without loading a new page, and it works on every browser except Internet Explorer, which is strange coming from an otherwise top-notch browser.
The form and iframe look like this:
<iframe id="hidden_upload" style="display:none" src="" name="hidden_upload" ></iframe>
<form class="" action="upload.php" method="post" target="hidden_upload" enctype="multipart/form-data" id="uploadForm">
<table>
<tbody>
<tr>
<td><label for = "title">Title: </label></td>
<td><input type="text" name="title" id="title" maxlength="40" style="width:300px;"/></td>
</tr>
<tr>
<td><label for="description">Description: </label></td>
<td><textarea id="description" name="description" style="width:460px;height:135px;"></textarea></td>
</tr>
<tr>
<td><label for="file">File: </label></td>
<td><input type="hidden" name="MAX_FILE_SIZE" value="3145728" /><input id="file" type="file" name="file"/></td>
</tr>
</tbody>
</table>
<center><input type="submit" value="Upload" id="filesubmit" onclick="return submitting()"/></center>
</form>
I have another page that DOES work in IE, with no discernible differences in the doc type, or form and iframe structure.
It's also not the headers from the upload page because I tried setting the action of the working form to the upload page of the non-working one and it still worked in IE.
The function submitting is working an returns true.
edit:
For the sake of brevity, this isn't working either:
<form class="" action="upload.php" method="post" target="hidden_upload" enctype="multipart/form-data" id="importForm">
<input type="submit" />
</form>
<iframe id="hidden_upload" style="display:none" src="" name="hidden_upload" ></iframe>
edit: This is completely ridiculous. I copied the working page verbatim into the non-working page and it still didn't work. The ONLY difference was the directory, and the .htaccess files were identical.
I had this problem and after many attempts, it was solved only as explained here:
"http://terminalapp.net/submitting-a-form-with-target-set-to-a-script-generated-iframe-on-ie/"
basically, iframe needs to be created this way:
iframe = document.createElement('<iframe name="fileUploaderEmptyHole">');
I also found out frame names for current window are stored in window.frames. In IE11, the property .name is empty for all iframes in windows.frames :O
I manually fixed like:
for(i=0;i<window.frames.length;i++)
window.frames[i].name = window.frames[i].frameElement.name;
Then, you can get to frames using target name.

form get method not working in opera browser

Why forms submited using get method is not working in opera browser?
<form method="get" action="">
I am submiting to same page
<form method="get" action="">
<table class="search_form_table" width="428" cellpadding="0" cellspacing="0" border="0" >
<tr>
<td width="150">Order Number</td>
<td><input name="order_number" /></td>
</tr>
<tr>
<td>Start Date</td>
<td><input class="search_date_fields" name="date_from" /> End date : <input class="search_date_fields" name="date_to" /></td>
</tr>
<tr>
<td colspan="2" align="right"><input class="subimit_button search_button_width" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
If this is the same problem I thought I had, it's not that GET doesn't work. It's because the browser hides the form name/value pairs in the query string in the Location bar. If you actually go to the location bar and hilite the URL that you submitted to, you'll see the form parameters in the query string. I hate this, but it is the way Opera does it. :-/
submitting GET forms certainly works in Opera. Copying this code to a file and submitting it creates exactly the same URL as in Chrome. Hence, your problem must be something else. Without more information it's impossible to tell what your problem really is.

Classic ASP on Localhost, no form data?

I have a really odd situation going on on my local PC that I can not seems to resolve.
Recently I have been contacted to extend a classic ASP website that I wrote a few years back. I unpacked the code into a sub folder of wwwroot on my current machine running XP pro. It has never had any classic ASP sites running on it. I set up IIS and create an application and run the website on my localhost. The site renders correctly and appears to run fine. Except one thing... The post data seems to get lost.
I have entered Response.Write("[" & Request.Form & "]") at the top of one of my pages and just renders "[]". Can any one advise as to why I may be losing the form data? The website used to work fine on my last machine running XP Pro, as that is the machine I developed it on. What have I forgotten to set up?
The html form code looks like
<form name="frmAdminLogin" actionAdminLogin.asp" method="post" >
<input type="hidden" name="hidFormAction" value="frmAdminLogin" >
<table width="80%" border="0" cellspacing="3" cellpadding="0" >
<tr>
<td width="40%" align="right" valign="top" >Username: </td>
<td width="60%" align="left" valign="top" >
<input type="text" name="txtUsername" value="" size="25" maxlength="25" tabindex="1" class="TextBox" >
</td>
</tr>
<tr>
<td width="40%" align="right" valign="top" >Password: </td>
<td width="60%" align="left" valign="top" >
<input type="password" name="txtPassword" value="" size="25" maxlength="25" tabindex="2" class="TextBox" >
</td>
</tr>
<tr>
<td width="100%" colspan="2" align="center" valign="top" >
<input type="submit" name="btnLogIn" value="Log In" tabindex="3" class="Button" >
<input type="reset" name="btnReset" value="Reset" tabindex="4" class="Button" >
</td>
</tr>
</table>
</form>
It appears that it is not an IIS issue after all but an Internet Explorer issue. The post data is present when I use Opera Browser.
I think this is correct - there is some bug (feature?) of Internet Explorer which prevents form data being submitted if there is only a single form element. If you add a extra element (hidden field, it really doesn't matter) it should work properly.
I'll try to expand this comment when I get a chance but my work firewall is preventing my finding the blog posts which originally pointed me in the right direction.

Safari 3.2.1 sends POST followed by GET requests

I've a servlet running on Tomcat 5.5.27 and 5.5.26 and have a web form with POST method.
If I use Safari 3.2.1 I see from the logs that Tomcat receives a POST followed immediately/contemporarily by GET and it fails.
If I use Firefox 3.0.5 I see that it sends only POST and everything works.
Trying to debug with Eclipse I see that when using Safari it is the doGet() method that is called while when using Firefox is doPost().
Practically it seems that Safari fires both POST and then immediately GET, while Firefox fires only POST (as it should according to the HTML form).
Is there somebody else who as experienced this ? In this case is there a solution ?
Here is a snippet of the HTML form:
<form action="/vidisearch/Search" method="post" name="SearchForm" id="SearchForm">
<div class="input required">
<label for="Concepts">Concepts, comma separated<br />
ex. (remove quotes) "man-made object, cemetery, graphic event, atmospheric event, tool event"</label>
<input name="concepts" type="text" value="" id="concepts" />
</div>
<div class="input required">
<label for="Operators">Operators, comma separated<br />
ex. (remove quotes) "NOT, AND, OR, AND, AND"</label>
<input type="text" name="operators" value="" id="operators" />
</div>
<div class="input required">
<label for="Specializations">Specializations, comma separated<br />
ex. (remove quotes) "true, false, false, true, false"</label>
<input type="text" name="specializations" value="" id="specializations" />
</div>
<div class="input required">
<label for="Results">Various parameters</label>
<table width="100%" border="0" style="border: 0;">
<tr>
<td>Ontology ID<br />
<input name="ontologyID" type="text" id="ontologyID" value="" /></td>
<td>Result page<br />
<input name="page" type="text" id="page" value="0" /></td>
<td>Shots per page<br />
<input name="shotsPerPage" type="text" id="shotsPerPage" value="20" /></td>
<td>New search<br />
<input name="newSearch" type="text" id="newSearch" value="true" /></td></tr>
</table>
</div>
<div class="submit"><input type="submit" value="Search" /></div>
</form>
I think you have an image tag that has an empty src.
It's hard to say without seeing your HTML for the form, but perhaps your submit button is a wrapped with a link, and Safari is both POSTing the form and following the link (via GET).
I'm not sure what's happening but what I do know is that you need to provide more information.
Maybe it's sending a GET for associated resources (like images) whereas Firefox keeps them in the cache, or you have the form submit button inside an <a> tag, for instance.
Another alternative is a Javascript incompatibility, in case you are submitting something via Javascript.
Sniff the traffic (check out Fiddler or Wireshark) and see what is Safari trying to GET and what's it is POSTing
I'm quite puzzled by the behaviour of Safari since I remind that sometime ago it worked. I'm fearing that one of the latest upgrades has broken something.
Using HTTPScoop I've seen that apparently Safari fires POST followed by GET when it gets the response. I think however that it actually fires both requests at the same time since the date+time of the two responses is the same for both POST and GET.
The response is a RSS feed and has the HTTP/1.1 200 OK code. The second GET asks for the same request URL (http://127.0.0.1:8180/vidisearch/Search) of the POST but the body is 0 bytes, it has of course no GET parameters and the answer is wrong because of the missing parameters.
Firefox instead fires only the POST and gets the correct answer.