Submit button with enter an url - javascript

I'm trying to create a bookmarklet, which captures the url of the current page, where the user is, puts this url into a text field of a form on a page and then submits the form by virtually pressing submit button.
With following code i get the url of the current page, go to the site with url http://example.com/?url=http://www.url-of-the-current-page, fill the url http://www.url-of-the-current-page into the form's text field, but the form itself remains unsubmitted:
javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href))})();
But how can i submit the form button? The whole form looks like:
<form ng-submit="launchTest()" class="ng-pristine ng-valid">
<input type="text" name="url" ng-model="url">
<input type="submit" value="Launch test" class="launchBtn" ng-class="{disabled: !url}">
</form>
I've tried two variants - and failed: in both variants i stay on http://example.com?url=http://www.url-of-the-current-page:
javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href));document.forms[0].submit()})();
javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href));document.forms[this.form.id].submit()})();

(Posted on behalf of the OP).
I've contacted the owner of the website, where I wanted to run my bookmarklet - he said, my bookmarklet is correct, but for submitting the form the url should contain a special parameter, like &run=1. With this parameter every bookmarklet mentioned in this thread works (works means not only opens new tab and inputs the url, but submits the form too). The working bookmarklet I'll use is:
javascript:(function(){var win=window.open('http://example.com?url='+encodeURIComponent(window.location.href )+'&run=1','_blank');win.focus();})()

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";

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.

Hide Confirm Form Resubmission PHP

After I submit a form, and I click the back button, the page displays the confirm form resubmission page. Instead of that, I actually just want the browser to display the form itself. It there a way to do that? Here is a part of my code below, and it works except that it will not stop refreshing. I just want it to refresh once when you click the back button.
<meta http-equiv="refresh" content="0">
<form method = 'post' action = 'submitPost.php?section=$section'>
<textarea rows='10' cols='100' name = 'post'></textarea> </br>
<input type = 'submit' value = 'Submit'>
</form>
This is a browser security policy - when you want to go back to a page you loaded using the POST http verb it will always ask you for confirmation.

Resubmitting the same form is not working

I am making an HTML page "Login Pro.html". I am making such a page where just clicking on a link I can login to an account (say Facebook).
HTML Code:
Login to my Account
The Form input fields for Username and Password (The value attribute will be set using JQuery):
<input type="text" id="username" value="" />
<input type="password" id="password" value="" />
<input type="submit" id="loginButton" />
In the JQuery code, I am setting the values and submitting the form like this:
$("#loginLink").click(function()//when the link is clicked this will be executed.
{
$("#username").attr("value","My Username");//Setting value for the username
$("#password").attr("value","My Password");//Setting value for the password
$("#loginButton").click();//Submitting the form by implicitly clicking the submit button
});
In this case I am able to login into my account successfully and the "Login Pro.html"(From the Page I am doing all these) is opening in a new page (because I have set target="_new" and the form is being submitted and taking me to the Home Page of the Account I am logging in into, is opening successfully in the first page (tab). But when I am trying to login again through the "Login Pro.html" page, opened in the new tab, I am being landed to the same page i.e. "Login Pro.html" page instead of getting logged in (In short in the second instance I can't login). After closing this page, when I am opening the page again, the same saga continues i.e. I am able to login in the first instance, but not able to do so while trying in the new tab.
Can somebody help me in getting rid of this. Is this because, the page is already loaded?
The "name" attribute is missing in the inputs. Without name you are not sending anything.

Thank you alert upon form submission

I have a very basic form at http://www.happyholidaylites.com/contact.html and it is working great. When you submit the form, the user is brought to the index.html with no message that the form has been sent. I am looking to initiate an alert that says, "your form has been submitted" with an x button. My code looks like this:
<form method="post" id="myForm" action="dynaform.php">
<input type='hidden' name='rec_mailto' value='JBIRD1111#gmail.com'>
<input type='hidden' name='rec_subject' value='New Contact Form'>
<input type='hidden' name='rec_thanks' value='index.html'>
so on and so forth.....
The last line is what is telling the form what to do after the submit button is pressed, but I dont want it to point the browser to the index, rather I want a javascript popup with a success message. Any ideas?
Why not a simple onSubmit?
<form method="post" id="myForm" action="dynaform.php" onSubmit="alert('Thank you for your feedback.');" >
To be honest you are better re-directing to another page in order to avoid the user re-submitting the page on a refresh. Have a look at Post/Redirect/Get Pattern.
Popups can be extremely annoying on websites. You should create a page called "thank-you.html" that you can re-direct the user to on successful submission which has access to the site navigation options or even just do a re-direct back to the form page after a few seconds.
Instead of redirecting to index.html, redirect to thanks.html; your users will thank you because everybody hates popups!
Sounds like your PHP script handles the form submission by processing the input and redirecting the browser to the value in the rec_thanks field.
You can add something like onsubmit="YourJavaScriptFunction()" to the form tag to add client-side behavior prior to actually submitting the form. Within that function you can perform validation, use alert('Thank You!'), etc..

Categories

Resources