The form:
<form name="htmlform" action="index.html" method="post"/>
<input type="text" id="companyname" name="companyname"/>
<span id='htmlform_companyname_errorloc' class='error'></span>
<input type="contact" id="contactperson" name="contactperson"/>
<span id='htmlform_contactperson_errorloc' class='error'></span>
<input type="submit" value="Submit"/>
</form>
Validation:
<script type='text/javascript'>
// <![CDATA[
var frmvalidator= new Validator("htmlform");
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("companyname","req","Please provide company name");
frmvalidator.addValidation("contactperson","req","Who is the contact person?");
// ]]>
</script>
How can I get a pop window if the form submitted successfully?
I think you need to redirect the user to page that has the popup screen for you
the case is:
if user submit the form
1.1.when not valid then stay in the same page
1.2.when is valid then (you can do this) go to another page / (or this) stay on the same page
you need to set variable when it successful submitted and then check it later on your view
Related
I have a form with id theForm which has the following div with a submit button inside:
<div id="placeOrder"
style="text-align: right; width: 100%; background-color: white;">
<button type="submit"
class='input_submit'
style="margin-right: 15px;"
onClick="placeOrder()">Place Order
</button>
</div>
When clicked, the function placeOrder() is called. The function changes the innerHTML of the above div to be "processing ..." (so the submit button is now gone).
The above code works, but now the problem is that I can't get the form to submit! I've tried putting this in the placeOrder() function:
document.theForm.submit();
But that doesn't work.
How can I get the form to submit?
Set the name attribute of your form to "theForm" and your code will work.
You can use...
document.getElementById('theForm').submit();
...but don't replace the innerHTML. You could hide the form and then insert a processing... span which will appear in its place.
var form = document.getElementById('theForm');
form.style.display = 'none';
var processing = document.createElement('span');
processing.appendChild(document.createTextNode('processing ...'));
form.parentNode.insertBefore(processing, form);
It works perfectly in my case.
document.getElementById("form1").submit();
Also, you can use it in a function as below:
function formSubmit()
{
document.getElementById("form1").submit();
}
document.forms["name of your form"].submit();
or
document.getElementById("form id").submit();
You can try any of this...this will definitely work...
I will leave the way I do to submit the form without using the name tag inside the form:
HTML
<button type="submit" onClick="placeOrder(this.form)">Place Order</button>
JavaScript
function placeOrder(form){
form.submit();
}
You can use the below code to submit the form using JavaScript:
document.getElementById('FormID').submit();
<html>
<body>
<p>Enter some text in the fields below, and then press the "Submit form" button to submit the form.</p>
<form id="myForm" action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="button" onclick="myFunction()" value="Submit form">
</form>
<script>
function myFunction() {
document.getElementById("myForm").submit();
}
</script>
</body>
</html>
HTML
<!-- change id attribute to name -->
<form method="post" action="yourUrl" name="theForm">
<button onclick="placeOrder()">Place Order</button>
</form>
JavaScript
function placeOrder () {
document.theForm.submit()
}
If your form does not have any id, but it has a class name like theForm, you can use the below statement to submit it:
document.getElementsByClassName("theForm")[0].submit();
I have came up with an easy resolve using a simple form hidden on my website with the same information the users logged in with. Example: If you want a user to be logged in on this form, you can add something like this to the follow form below.
<input type="checkbox" name="autologin" id="autologin" />
As far I know I am the first to hide a form and submit it via clicking a link. There is the link submitting a hidden form with the information. It is not 100% safe if you don't like auto login methods on your website with passwords sitting on a hidden form password text area...
Okay, so here is the work. Let’s say $siteid is the account and $sitepw is password.
First make the form in your PHP script. If you don’t like HTML in it, use minimal data and then echo in the value in a hidden form. I just use a PHP value and echo in anywhere I want pref next to the form button as you can't see it.
PHP form to print
$hidden_forum = '
<form id="alt_forum_login" action="./forum/ucp.php?mode=login" method="post" style="display:none;">
<input type="text" name="username" id="username" value="'.strtolower($siteid).'" title="Username" />
<input type="password" name="password" id="password" value="'.$sitepw.'" title="Password" />
</form>';
PHP and link to submit form
<?php print $hidden_forum; ?>
<pre>Forum</pre>
i am building a form and when i submit it it opens the action url. I want to submit the form on click button which should not open the target url but submit the request. as well as i want to print a message after submit and form should be cleared after submit.
<form id="contact" action="https://control.msg91.com/api/sendhttp.php" method="post">
<h3>Send SMS</h3>
<h4>Build in Process</h4>
<fieldset>
<input name="authkey" type="hidden" value="auth key as required"/>
<input name="mobiles" placeholder="Mobile Number" type="text" tabindex="1" maxlength="10" required >
</fieldset>
<fieldset>
<textarea name="message" placeholder="Type your message here...." tabindex="2" maxlength="320" required></textarea>
</fieldset>
<input name="sender" type="hidden" value="FAKEin" />
<input name="route" type="hidden" value="4" />
<input name="country" type="hidden" value="0" />
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
</fieldset>
</form>
any help how can i do this?
also can i add a hidden text in message tab that should add to the message tab in post/get as + instead of &
eg. actionurl.php?authkey=custommade&mobiles=9999999999&message=orginal+message+hidden+message&sender=FAKEin&route=4&country=0&submit=
You can also check the source code of page https://www.tricksbygoogle.com/sms/sms.php
Basically You can't .
The only solution here I see , is using ajax query and use javascript to clear form.
This example I provide is no redirections at all. What means you page will not be reloaded.
Maybe little jquery will help.
var result_func = function(response){
if(response.allOk){
$this.reset();
}
}
$('#contact').submit(function(e){
e.preventDefault()l
var $this = $(this);
var data = $this.serialize();
$.post($this.attr('action'),data,result_func.bind($this));
});
Header location will work , but user still will be redirected.
Based on your question, and the comments it looks like you're going to have to do a little bit of research. Here are some tips though.
If you would like to include the functions from a page without actually visiting the page, than you can use what is called an include statement. This will keep the browser from visiting that page while still executing it. - http://php.net/manual/en/function.include.php
To display a message you're going to need to hide and show the element with javascript. I would suggest viewing this question - Hide div after a few seconds
Basically on submit, you're going to want to check for the variables from your form. You would run a php if statement.
Then, if those variables exist you are going to want to include your action page.
In the same if statement, you're going to want to echo a <div> with a class that has some javascript attached to it to hide it after a few seconds.
The form will automatically clear on submit.
if($variable != null){
include '/action.php' // --- you can add some GET variables to the end of this if you would like to.
echo '<div id="message">Message sent</div>'
}
Page1.JSP
//input text box
Enter Form id:<input type="text" name="formID" id="formID" >
Show Form
This returns a null value. In page2. JSP
//get the input value
<%String formsubmitID=request.getParameter("formID");%>
This returns null. I am not able to parse. I tried all the methods using window.location, adding a button adding a href link but i am not able to access the input text field and redirect both at the same time. Here is the code for first JSP Page from which I need to redirect to another JSP Page with the input text field entered at Firest JSP Page.
I tried using a button and redirect in Java script
//javascript for redirecting to another page
function redirect(elem){
alert("in redirect Method:")
elem.setAttribute("action","Page2.jsp");
elem.submit();
return false;
}
// Page1.JSP
<form ACTION="Page2.jsp" METHOD="POST" onload='onload()'>
Enter Form id:<input type="text" name="formID" id="formID"/>
<INPUT TYPE="SUBMIT" value="Submit" onclick="redirect(this);">
</form>
This also doesn't work. Redirect doesn't happen at all when I am using window.location.href or window.location.
Please help me find the solution for the same.
When you are using form than whenever you click on button you will be directed to Page2.jsp (i.e. url mentioned in form action) like
<form ACTION="Page2.jsp">
Enter Form id:<input type="text" name="formID" id="formID"/>
<INPUT TYPE="SUBMIT" value="Submit">
</form>
In Page2.jsp get value of text field like
<%String formsubmitID=request.getParameter("formID");%>
I want to submit the another website submit button from my website using javascript, is it possible..? My Code are below:
<script type="text/javascript">
function formSubmit() {
document.getElementById("form1").submit();
}
</script>
<form name="form1" method="post" action="http://XXXXX/Login.aspx?ReturnUrl=%2fdefault.aspx?" id="form1" >
<input type="hidden" name="NewCorporateId" id="NewCorporateId" value="XX" />
<input type="hidden" name="UserName" id="UserName" value="XXXX" />
<input type="hidden" name="Password" id="Password" value="XXXX" />
</form>
<form name="form2" id="form2" method="post>
Click here
</form>
Specified URL opened fine in new tab and button not submitted in that
site. That site contain the one submit button and username and
password text filed.. I have username and password value.. So i try to
submit the button in referring site from my website.
Its possible and the post code is correct, but because you post on aspx page Login.aspx, aspx pages protect from sending data that is not come from the same site by adding a hash code of controls. Also there is the ViewState of the page, and other hidden parameters added by aspx - so your call will fail.
Contact with the one that handle the login.aspx page to give you some way to login there - not direct by the page.
related :
What is the purpose of __EVENTVALIDATION __VIEWSTATE in aspx?
I have a form like this:
index.php
<form method="post" action="send.php">
<textarea name="msg" id="msg"></textarea>
<input type="submit" value="Send" />
</form>
So, if I enter something in textarea and clicked on "Send", it is submitted to "send.php" page. But I want to include another button for previewing it. That is, when this button is clicked, the above form is submitted to "preview.php" which will be opened in a new blank window/tab (original page ie. index.php will be there intact). This is to display a preview of the message, that the user is going to send.
I do not know how to do this.
Use Javascript to temporarily change the action and target:
<form method="post" action="send.php" id="idOfForm">
<textarea name="msg" id="msg"></textarea>
<input type="submit" value="Send" />
</form>
<button onclick="doPreview();">Preview</button>
<script type="text/javascript">
function doPreview()
{
form=document.getElementById('idOfForm');
form.target='_blank';
form.action='preview.php';
form.submit();
form.action='send.php';
form.target='';
}
</script>
There is now an attribute for the submit input that handles this:
<input type="submit" formaction=”differentThanNormalAction.php”>
Give your form an ID (form1). The action of the current form can be controlled like this:
function setPreview() {
$('#form1').attr('target','_blank')
$('#form1').attr('action','http://yourpreviewurl.php')
$('#form1').submit()
}
function setSubmit() {
$('#form1').attr('target','')
$('#form1').attr('action','http://yourposturl.php')
$('#form1').submit()
}
Have two buttons, both type="button", one to call setPreview and another to call setSubmit
You can use JavaScript to change the action of the form when the button is clicked and then submit it.
Or simply submit the form via AJAX and then redirect after you get a response.
<form onreturn="someJavascriptFunction()" action="" method="">
creating a js function able to open this preview page