Coldfusion url variable - javascript

I have a basic question here not been able to get it right....
I have a ColdFusion form abc.cfm and on submit posts to
<form name="MyForm"
method="post"
action="abc_action.cfm?vempnum=
<cfoutput>#qGetemplookup.emplid#&year=#form.year#</cfoutput>"
Now I have a textbox and a select box and I'm able to get the emplid value on the action page in the url but not able to get the year (which is the select box value)...not sure what I'm doing wrong here. Any help is appreciated.

If I understand the question correctly, you are trying to access form.year prior to actually submitting the form that the year input exists in. This won't work because the form scope will only be populated once the form has actually been submitted.
Trying to add form.year to the URL of the action is actually redundant, because when you do POST the form, the value selected for year will be available to you as part of the form struct.

ColdFusion renders the action when the page is rendered to the screen. So, #form.year# is being populated with whatever it is set to when the page loads.
You're submitting via POST method, so form.year is automatically populated when the processing page (abc_action.cfm) receives the form submission.

Wrap your form tag with CFOUTPUT and place the variable in there.
For example:
<cfoutput>
<form name="MyForm" method="post" action="abc_action.cfm?vempnum=#qGetemplookup.emplid#&year=#form.year#">
</form>
</cfoutput>

Related

Add hidden form variable to the end of the URL

I have searched Unbounce and Google for documentation, but can't find a way to make this work. Any help is greatly appreciated!
Use case:
I have a test page setup in Unbounce and it would be great when a user lands on the page and submits the form that the value being generated through the script below in the hidden field is added to the current URL upon submission.
It's important that if the user lands on the page from an advertising campaign that the value is added to URL and does not replace it.
Example:
User lands on testpage.com or testpage.com?qs=3134728&pcd=THANKS20&dclid=CNi4wvCv39cCFZdFNwodE_wALA
Unique ID is created with the following JavaScript and added to a hidden field:
<script type="text/javascript">
$(document).ready(function() {
var id = new Date().toISOString().replace(/[-tTzZ:.]/g, '');
$('#lead_id').val(id);
});
</script>
User clicks submit and and is redirected to a thankyou page with the value of the hidden field passed in the URL:
testpage.com/thank-you?lead_id=1234
testpage.com/thankyou?qs=3134728&pcd=THANKS20&dclid=CNi4wvCv39cCFZdFNwodE_wALA&lead_id=1234
I should also mention that I can not edit the html of the form so this would need to happen with JavaScript as Unbounce provides a space to add custom code.
Is the form method get? If it is post it wont append that to the URL for the hidden field.
Your approach seems right however if this is the HTML on page:
<form action="http://example.com" method="get" id="theForm">
<input type="hidden" value="xyz" />
<button type="submit">Send</button>
</form>
You can use some JS code like one of the following to modify this...however you'll want to verify that everything still works as expected:
document.getElementById('theForm').action = "http://another.example.com";
document.getElementById('theForm').method = "get";

How to stop Redirecting a page when a form is submitted?

I'm using a form and when the form is submitted I used action attribute and called a server url where the form data gets saved
Here's how it looks :
<form name="example" action="webresources/data/update" method="post">
</form>
The above form when submitted updates the form data in to the server but at the same time it also takes me to the new page webresources/data/update which has nothing but server response
I don't want this response to be shown on the web page. The url should be called when the form is submitted and it should be on the same page without redirecting to a new page.
Is there any way to do this, I'm allowed to send the data only via form parameters.
Thank you in advance :)
Remove the action attribute in the form and put the button outside the form.
When onclick, make an ajax call.
<form>
stuff
</form>
<input type="button" onclick="ajax()">
<script>
function ajax(){}
</script>
<form name="example" action="webresources/data/update" method="post" onclick="return false">
</form>
Returning false will stop the page from reloading or refreshing.
I suggest that before you ask a question you do a quick google search because this was the first result that came up for me prevent form submit from redirecting/refreshing using javascript.

Redirect the website URL Form to a particular Page

My Form Works Successfully But in website URL it only Shows the address to a Form.I have multiple Pages in which the Form button shown.All I want when a user click on The Form for Page A for that Particular page it should shown as
"www.form.com?test=page A" - this should displayed on website URL
or when the Form is submitted the receiver should view that this form coming from Page A..In the Form field I hidden this fields name 'Test' so the user cannot see it but only the receiver can view it that its coming from Page A
On my Html code I have redirected to the Build in Form.
Here is my java script code
<script type="text/javascript" src="http://test.com/form/y.php/test2"></script><no1script>Online Form - </no1script>
How to show it to my Website URL
I understand your question as "How can I redirect with a specific GET parameter?", correct me if I'm wrong.
The solution for that would be quite simple: Append the GET parameter to the forms action:
<form action="target.php">
gets
<form action="target.php?test=page_a">
so that on target.php if you evaluate the GET values, test has the value page_a.
If you're trying to hide the post data, you can try something like:
<form action="https://test.com/forms/discount" style="display:none">
<input type="text" name="couponCode" value="secret">
<input id="myform" type="submit">
</form>
<script>
document.querySelector("#myform").click();
</script>
Note: This won't stop any web ninjas, so you should think of something else, like web tokens that function sortta like private public keys.

Sending data to php script without ajax

I am required to send data from an html page, via input elements to a php script and I cannot use ajax for some reason. How to accomplish this?
My code is something like this:
HTML:
First Name : <input type"text" name="first_name">
<br><br>
Last Name : <input type"text" name="last_name">
<br><br>
<button id="submit_btn">Submit</button>
Now, I want the javascript to be something like :
function redirect_from_here() {
close(); //close the current window
window.location='./phpfile.php'; //load the new page which will process the data sent to it.
}
My question is how do I send the value in the input elements in the HTML portion, as data to be processed, to the php script (phpfile.php in this case).
Please note that I prefer not to use html form for doing the job.
You are using HTML form as there are input fields in you code.
Inputs are part of a form and should be wrapped by a form element
Why using JS for submitting the form when you can use <form action='script.php'.. for that?
I suggest that you revise your requirements instead of trying to come up with a hackish way of how to send the data..
Just submit a form with action="phpfile.php"
if not interested with html,
then in the window location bind the values as a GET form method do

html Form not recognized in my jsp page

I have a JSP page which is included in the main page..Within the JSP page, I have given a HTMLform which I want to submit() once the user clicks it using Jquery?
<form id="orderBean1" name="myForm" action="/Auto/Item" method="post">
<input id="filename" name="filename" value="" />
</form>
First,
Suprisingly, this form is not recognized within the page..
When I give $('#orderBean1') in my console it does not give the form object whereas $('#filename') gives me the filename input element.
Second ,
As the form is not recognized it does not get submitted...
$("#vehreport").click(function(e) {
e.preventDefault();(I have given this stmt even after the submit() and still not working...
$("#orderBean1").submit();
alert("formsubmnittted");
})
Question -
Why doesn't the form element is recognized in my page?
I set up a JSbin here.
As you can see, #orderbean1 is recognized, and submits.
The error is likely elsewhere is your JS or markup, though if I'm misunderstanding the question please clarify

Categories

Resources