Handling two forms from a single jsp - javascript

I have 2 forms in my jsp. The first form is a regular form which contains the user information. The second form is to submit the data to a third party api using its https url.
1st Form:
<form action"\doProcess">
<input type="text" id="email" value=""/>
other user details and inputs
</form>
2nd Form:
<form action="https://thirdpartyapi.com/do">
//email from first form
email to submit
</form>
So the email value must be from the first form email input value. I have tried to complete this using ajax instead of using the second form but there are cross domain policy restrictions which made me to come back to use two different forms. So here both forms must be submitted one after the other. Can any one please let me know how can i do this? Thanks in Advance.

Related

How to make a button in HTML that will send the current page of a website via email?

Let's say I have a website where there is a button. When you click on this button the website will send the current page html (either as the body of an email or as an attachment ex: index.html) to a specific email address. Is this possible? If so, how? (I want to do it in either with html tags or javascript).
It's like sending a form but instead you send an html page.
What you're describing looks to be a use case for NodeMailer. Assumption here is that you're using Node.js as your backend. There are many options for other languages pypi-mailer being a common option for python.
Regardless, you would need to have a html form (or a default option of email)
<form action="/sendMail">
<label for="email">Email: </label><br>
<input type="text" id="email" name="email" value="Enter your email"><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be send to an endpoint /sendMail".</p>
Then you would need Javascript on the front-end to actually get the object. I believe this answer is what you're looking for here.
This link explains how to actually use nodemailer to send an email.
Hope this helps!

Jekyll site html form which submits to a different page but redirects to another

I have a Jekyll site and a contact page on which I made a simple form and connected it with service like FormSpree or SimpleForm which automatically sends the responses to my inbox, what I would like to do is redirect to a Thank you for your response page after the form is submitted. Attempted this in many ways like adding event listener to the submit button or using onSubmit or action properties of the form but I was only able to achieve one of the two things, either the form submits or I am redirected to the Thank You Page, unable to perform both when I have no access to the server side script which I could have used for redirection. The form is pretty basic, a few input fields and a submit button. Would appreciate any form of help.
Both services allow a hidden field, in your form, which points to the thank you URL you want to be redirected after submission.
with FormSpree use _next (see advanced features)
<input type="hidden" name="_next" value="https://my-site.tld/thanks.html" />
with SimpleForm use redirect_to (see the sample code in their page)
<input type='hidden' name='redirect_to' value='https://my-site.tld/thanks.html' />

How do I create a form that only allows one submission per day per user in HTML?

I am pretty new to HTML forms, but I am trying to limit 1 submit request per user, per day. So I don't have any people spam it. I am not the best coder, but not the worst.
Example (in words, not code):
If user has not submitted the form today:
Form allows person to submit.
If user HAS submitted the form today:
Form does not allow person to submit form, notifies them as well.
Please note this in HTML and JavaScript only please!
I do not think that you can do this with only client side technologies (like HTML and JS) since they're session based. If a user opens a different browser or even closes and opens the same browser, the JS and HTML are 'new' again. You could limit it per browser if you used a client side cookie that stored the submission and the time stamp, but it would not prevent the user from submitting again using a different browser.
Here is a link about cookie creation and reading: Set cookie and get cookie with JavaScript
html and js only solution:
if (confirm("have you made a request today? 'OK' means YES, and 'Cancel' means No")) {
document.getElementById("submitBtn").disabled = true;
} else {
document.getElementById("submitBtn").disabled = false;
}
<form>
First name:<br>
<input type="text" name="firstname"><br> Last name:<br>
<input type="text" name="lastname"><br>
<button type="submit" id="submitBtn">Submit</button>
</form>
yah, not really possible. sessions or cookies can be easily bypassed as others mentioned...
You could try to prevent spam with a captcha.

POST form data to another form inside an iframe

So i am running a JX Browser which allows content to be shown in an iframe. When someone logs into my ticketing software i want to post their username and password to another form in an iframe.
Basically the iframe contains a page in which i want them to be automatically logged in to. The login credentials for the ticketing software and the page are the same all i want to do is pass that credential to an iframe in which there is username and password field.
Like in jquery you can get .val of the what every is submitted and just send it to another form field.. i want to do that..
What is the best practice?
You can set target attribute on a form to point it to an <iframe> by name.
For example:
<form action="process_login_url" method="post" target="iframelogin" id="loginform">
<input name="login" type="hidden" value="login" />
<input name="password" type="hidden" value="p4ssw0rd" />
</form>
<iframe name="iframelogin">
<script>
// automatically post the form
document.getElementById('loginform').submit()
</script>
You need to pre-populate the hidden fields with user login and password, then the form is automatically sent to the iframe. action on your form has to be the other login processing url, not the login form itself (if these are separate). So basically the action attribute of the external form. Names of the input fields also have to match the target form's names.
Example: http://jsfiddle.net/297suggf/2/ - note the iframe has no src attribute, it loads the url from action on the form with the POST data passed with the request. (It's some random website that allows testing POSTs).
I don't think it's a great idea, and it may not work if there's a protection on the receiving end (like a CSRF token), but youu may give it a shot if it's a last resort type situation

POST method of parameters from asp page

I have a page with a regular form:
<form method="post" action="pro.asp">
<input type="text">
<input type="submit">
</form>
when it gets to the pro.asp page it will do some server side actions like sending mail and then I need that page to send all the parameters in the post request to another website
I don't want to have another form filled auto and auto submit with javascript script
Is there a solution for that?
Do you have to make a POST to the other website?
The simplest thing to do may be to, when you are finished your own form processing, send the values to the other page as a GET.
To do that all you would need to do is end your processing with a response.redirect.
Response.Redirect ("http://somewebsite.com?value=X")

Categories