Student newb here working to construct a history of my class assignments in a manner which is helpful to me for future reflection; Currently I'm doing a form assignment, which works but i'm trying to push it a touch to get the most out of the experience. My goal is that if i click the 'reset' button the form will clear regardless of if i've clicked the submit ('continue') button or not. Currently if i click the clear button before clicking the submit button, the form data will clear. But if i've clicked the continue (to submit the form to self and the form data is now sitting on in the url), the data will not clear.
this is my javascript function
<script>
/* JS to clear form */
function myFunction() { document.getElementById("myForm").reset(); }
</script>
this is the whole form part of the code:
<form enctype="multipart/form-data" action="./itc216.php" method="get">
Name: <input ="text" name="userName" value="<?php echo $userName; ?>" />
<span class="error"><?php echo $errorMessage1; ?></span><br /><br />
Amount: <input ="text" name="mealTotal" value="<?php echo $mealTotal; ?>" />
<span class="error"><?php echo $errorMessage2; ?></span><br /><br />
<input type="checkbox" name="agreement" <?php echo $agreement; ?> />
Do you agreement to the terms and conditions?
<span class="error"><?php echo $agreementError; ?></span><br /><br />
<input type="submit" name="submit" value="Continue" /> | <input type="reset" onclick="myFunction()" value="Reset!">
</form>
Reset does not clear the form, but resets the form to its default values. If you are pre-populating the form inputs with the submitted data, those are what the form will reset to. If that's the case, to clear the form, you will need to have Javascript set all values to empty.
You may need to use event delegation
$('#clearbutton').on('click', function(){
$("#myForm").reset();
});
It sounds like you want to redirect after processing the form, so that the URL is clear.
This is generally a good idea even when doing a POST, so that refreshing the page doesn't create a new entry.
I guess you aren't really processing the form yet so you don't have a way to display the entry unless it's in the URL, but that would be the correct way to do it.
You Forgot to add the id for the form in the form add
<form enctype="multipart/form-data" action="./itc216.php" method="get" id="myForm">
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>'
}
What i want is pretty simple, i have a button that submits a value to my database once clicked, what i need is to diable the button parmanently after value has been submited, i have searched and the codes i have seen all enable the button when the page refreshes.. please can someone help me out?
My form and button code as follows:
<form action="<?php echo $editFormAction; ?>" method="POST" name="Status2" id="Status2" onSubmit="return confirm('Are you sure you want to submit?');">
<input name="Confirm2" type="checkbox" id="Confirm2" value="Confirmed" checked="CHECKED" style="display:none;">
<label for="Confirm2"></label>
<input name="UpdateButton3" type="submit" class="art-button" id="UpdateButton3" value="Confirm"/>
<input name="UserIDHiddenField4" type="hidden" id="UserIDHiddenField4" value="<?php echo $row_User['UserID']; ?>">
<input name="Purge2" type="checkbox" id="Purge2" value="You Will Be Rematched Soon!" checked="CHECKED" style="display:none;">
<label for="Purge2"></label>
<input type="hidden" name="MM_update" value="Status2">
</form>
First of all if you submit it, this has nothing to do with javascript. Save this in your database as #georoot says. Then when you submit, save a value in the database. If that value is set, you can disable the button by just HTML:
<input type="submit" <?php if($valueFromDatabase==1){ ?> disabled <?php } ?> >
Best solution could be to set a cookie on client system and/or get user IP and save it into your database, but you should keep in mind, non of them are permanent ! The IP can be changed and the cookie can be removed ! But you can use both cookie and IP check.
Then for each page load, just check if cookie exist (compare the value with ur database value) and/or client IP is already exist in database.
Or if you know who is on the page (if it's a logged user) just add a field in your database and set value = 1 or = 0 and check the field each time it's loaded for same field and for same user.
I wouldn't recommend to use IP check without cookies ! Because it can change frequency !
I have a form that I would like to submit automatically on page load however it is submitting a blank form.
This is the manual code, when I click submit either yes or no is posted without a problem.
<form method="post">
<label>Do You Authorize <?php echo $this->escapeHtml($this->clientId) ?>?</label><br />
<input type="submit" name="authorized" value="yes">
<input type="submit" name="authorized" value="no">
</form>
This is the automated code:
<body onload="document.getElementById('myForm').submit();">
<form method="post" id="myForm">
<label>Do You Authorize <?php echo $this->escapeHtml($this->clientId) ?>?</label><br />
<input type="submit" name="authorized" value="yes">
</form>
The automated code is submitting perfectly, however when I dump the $_POST variable, it is empty.
Any ideas why?
Try changing your <input type="submit"> to a <input type="hidden">. It may be that because no one is actually clicking the submit button, the value isn't getting passed.
I'm trying to make a 'Choose Your E-mail Plan' page on my website - https://godesignweb.co.uk/e-mail-services/monthly-email/ & I'm having trouble submitting the form, and then redirecting to a specific paypal page depending on what package they've chosen.
As you can see from the website it's almost there, and depending on which package you choose, it displays a different at the bottom of the page.(which I want to contain a submit button which redirects the user).
I currently have
<input type="submit" form="email" value="send">
which is outside of the contact form 7 form, and works (it's on the Pro plan) if you click it, it submits the form.
Is there anyway I can call 3 different functions for the 3 buttons which;
1) submit the form (including checking the validation that it normally does_
2) redirect the user to a paypal page
Cheers
Updated answer:
As taken from your comment to my answer, here's what you could try if you use three different submit buttons:
1.) assign each SUBMIT button a unique name:
<!-- button in starter form -->
<input type="submit" name="submit-starter" form="email" value="Send"/>
<!-- button in pro form -->
<input type="submit" name="submit-pro" form="email" value="Send"/>
<!-- button in advanced form -->
<input type="submit" name="submit-advanced" form="email" value="Send"/>
2.) On PHP side:
if (isset($_POST['submit-starter'])) {
$plan= 'starter';
$priceMonthly= 3.99;
} elseif (isset($_POST['submit-pro'])) {
$plan= 'pro';
$priceMonthly= 5.99;
} elseif (isset($_POST['submit-advanced'])) {
$plan= 'advanced';
$priceMonthly= 7.99;
}
// create the Paypal form
?>
<form name="_xclick" action="https://www.paypal.com/de/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="me#mybusiness.com">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="<?php print $plan; ?>">
<input type="hidden" name="amount" value="<?php print $price; ?>">
<input type="image" src="http://www.paypal.com/en_GB/i/btn/x-click-but01.gif" border="0" name="submit" alt="Pay with PayPal">
</form>
-- previous answer --
I am not sure if I got you right because I somehow just see one (submit) button instead of three buttons so I hope my answer is not misleading or doesn't make sense in your scenario:
I assume that:
the three buttons refer to the three plans you offer
you only want to have one validation function
based on the plan selection you want to have different prices on the Paypal checkout form
The below code will only deal with the frontend control, you should definitely add a second server-based verification to make sure nobody injected/manipulated your frontend form code.
Instead of using a standard submit button, change it to:
<input type="button" onclick="formInspectAndSubmit()" value="send"/>
and add a form variable for your plan
<input type="hidden" id="input-plan" name="input-plan"/>
Your FRONTEND validation function should look like this:
function formInspectAndSubmit() {
// validation stuff ...
// retrieve the chosen plan
var plan= $('.active').prop('id');
switch (plan) {
case 'starter':
// set hidden parameters for starters
$('#input-plan').val('starter');
break;
case 'pro':
// set hidden parameters for pro
break;
case 'advanced':
// set hidden parameters for starters
break;
}
// set POST variables based on above plan and redirect to validation page; this should then forward to Paypal checkout page with price defined by chosen plan
$('#email').submit();
}