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
Related
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' />
I am working on example.com, when some one logged on my site I would also want to check his authentication on abc.com, abc.com accepts POST request to check authentication.
I was thinking to use an iframe which auto submit a request to abc.com (along with exaple.com ) and set a cookie in abc.com domain too.
Please suggest me if there is any better way to handle this?
Could some one reply with an example how to submit an iframe with post params?
Thanks in advance!
Not sure that iFrame is the best practice here, but you can render a form inside your iFrame and submit it onload.
Of course you will need to pass some data to the form, so you can pass it via the src url with query string params and grab it inside the iFrame.
For post request you will need to set the form (inside the iFrame) as method="post"
You can set a form's target attribute to submit to an iframe:
<form name="frm1" id="frm1" action="http://someurl.com" method="post" target="myiframe">
You may also consider just using an ajax call with jQuery instead and set the httpmethod to "post", which is what I would do.
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.
Is it possible to create a contact form that sends the answers by email with only HTML5 and JavaScript? And if it is, how do I do it?
I don't think it's possible to do it from JavaScript directly via a mail function or so because the user's local machine can't be assumed to be running a mail server. There would be nothing to send the email from.
I'm not sure how "standards compliant" this is, but you can navigate to (by using links or document.location) to mailto:user#example.com or so which will begin composing an email in the user's standard email client, allowing them to send you an email directly. Though this will expose both their and your email address.
In the action field of the form, set the action as “mailto:youremailaddress” for example:
<form action="mailto:myforms#mydomain.com">
If you want to send the form data as plain text you can use the following
Add ‘enctype=text/plain’ in the form attributes. The form code becomes:
<form action="mailto:myforms#mydomain.com" enctype="text/plain" >
When this form is submitted, you will get the email in readable form.
I have My request parameters in the URL of current page. When I click on submit in the same page, parameters lost got lost in the new request. How to retain the request parameters even after submitting the form?
You can read the query params from the url and add them as a hidden fields into the form you are submitting. This will send the query string params along with the form.
Send the request parameters as form's GET params
Have the server set the parameters in a cookie so it is available in every page.
Put it in browser's local storage.
If submitting the form via POST, you can include request parameters in the form's action attribute, eg
<form method="post" action="action?id=123&foo=bar">
<input type="text" name="baz">
<input type="submit">
</form>
What you are asking for is state management. It can be done in several ways
HttpSession
Cookies
Hidden fields
URL rewriting.
Hidden fields is an easy way to do it; although the HTML can get more lengthy. I personally prefer HttpSession.