How to Prevent Duplicate Form Submissions [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have simple email script with few forms and I am getting duplicate submissions...
So, what is the easiest way to prevent duplicate submissions?
My code..
<form action="main_contact.php" method="post" name="contact_form">
<input type="text" name="contact_name" placeholder="Name">
<input type="email" name="contact_email" placeholder="Email">
<input type="text" name="contact_subject" placeholder="Subject">
<textarea cols="30" name="contact_message" rows="10" placeholder="Your Message"></textarea>
<input type="submit" value="Send">
</form>
<?php
if(isset($_POST['contact_form'])){
var_dump($_POST);
}
?>

You can use jQuery to disable submit button after the form has been submitted:
$('form[name="contact_form"]').submit(function(){
$(this).find('input[type="submit"]').prop('disabled', true);
});

you just need to disable or make visibility hidden after just click on submit button. fist give a id to the submit button
<input type="submit" value="Send" id="sub_id">
and then make it hidden or disable in javascript once you submit the form
document.getElementById('sub_id').style.visibility='hidden';

If you used any framework like Laravel5 or Symfony you would get it "out of the box".
In short:
Register a session token and invalidate it after first form submission.

Related

html form not using POST - acting funny [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I made bootstrap a form with this code and i am loosing my mind, not knowind why upon submitting is doing a GET method and redirecting to
tables.php?type=addTable&tablename=test&tablenumber=4#
And not to: essentials/settings-bar.php
<form action="essentials/settings-bar.php" method="post">
<input type="hidden" id="method" name="type" value="addTable">
<input
type="text" class="form-control col text-center m-1"
id="tablename" name="tablename"
placeholder="Table name"><br>
<input type="text"
class="form-control col text-center m-1" id="tablenumber"
name="tablenumber"
placeholder="Table number""><br>
<input type="submit" class="btn btn-primary m-2" value="Add table">
</form>
There was an unwanted hidden in the code, that i forgot about it

PHP & HTML - Getting user input and going to another page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
NOTE: Possible duplicate question is not helpful, as it does not compensate for multiple options for different pages while also passing form information.
I need to take user input from the current page (for now, this is just a single text field), and there are three buttons. The three buttons are supposed to go to different pages respectively, but all three need the value from the text field to do their job.
Essentially, I need to "pass" the value from the text field to either of the three pages that the buttons should redirect to. Currently, the buttons are unable to redirect as I do not know how to do that.
This is my code thus far:
<html>
<body>
<form name="form" action="" method="post">
Name: <input type="text" name="name" value="<?php echo $name;?>">
</form>
<button type="button">button1</button>
<button type="button">button2</button>
<button type="button">button3</button>
</body>
</html>
No JavaScript please.
<?php
if(isset($_POST['button1'])){
$link='index_1.php?name='.$_POST['name'];
header('location:'.$link);
}elseif(isset($_POST['button2'])){
$link='index_2.php?name='.$_POST['name'];
header('location:'.$link);
} elseif(isset($_POST['button3'])){
$link='index_3.php?name='.$_POST['name'];
header('location:'.$link);
}
?>
<form action="" method="POST">
Name: <input type="text" name="name" value="">
<button type="submit" name="button1" value="button1">button1</button>
<button type="submit" name="button2" value="button2">button2</button>
<button type="submit" name="button3" value="button3">button3</button>
</form>
The page where a form leads to is defined in its action attribute of the formtag. Just write the filepath + filename into that attribute and after submitting, you'll be redirected to that page and can use the POST parameter values there.
But you'll need to add a submit button - one, not three, and as an input tag
Use the submit type, and the check the value for the submitted (or the name you want to put it) in the PHP file, if the value is "button1" do something, if its "button2" etc.
<form action="/action_page.php" method="POST">
Name: <input type="text" name="name" value="<?php echo $name;?>">
<button type="submit" name="submited" value="button1">button1</button>
<button type="submit" name="submited" value="button2">button2</button>
<button type="submit" name="submited" value="button3">button3</button>
</form>

Signup form: email and submit on the same [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
At the bottom of my site, I have a sign up form. I can't make the button to be on the same line and close to that the email.
It already has a class assigned, so it's just about the css, but I'm no expert on css :(
Here is the HTML Code:
<div class="mc4wp-form-fields"><h1 align="center">
Want to hear updates on the future releases?
</h1><br>
<input type="email" name="EMAIL" placeholder="Your email address" class="signup" required="">
<input type="submit" value="Sign up" class="signup_button">
Any Idea how to do it???
Your input has a width of 100% - therefore taking 100% of the container.
input[type="email"] { width:/*something thats not 100%*/ }
You could float them, providing neither is set to 100% width...
<input style="float:left;" type="email" name="EMAIL" ....
<input style="float:right;" type="submit" value="Sign up" ....

When I click in my newsletter subscribe button in my footer Im going to the top of my page [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
When I click in my newsletter subscribe button in my footer Im going to the top of my page.
I can have my sucess message my error messages but Im going always to the top of my page. And I dont want this because I want that usre see the feedback message without scroll down to my footer.
Do you see why this happening and how can I fix this?
<form action="" name="newsletter" method="post" enctype="multipart/form-data">
<div id="email_newsletter_container">
<input type="text" id="email" value="<?php if(isset($_POST['email'])) echo $email; ?>" name="email" placeholder="Insert your email..." required/>
<input type="hidden" name="newsl_sub" value="subscribe" />
<button class="btnn" type="submit" name="subscribe"><span>Subscribe</span></button>
</div>
</form>
When you put action="" the action will reload the page. If you put action="#newsletter" it should take the user to the section of the page that contains the form when the form is submitted. You may also want to add id="newsletter" to the form to ensure compatibilities.
<? if($post_was_submitted_and_comment_was_inserted) { ?>
<script>
window.addEventListener("load", function(){
document.getElementById("comments").scrollIntoView();
});
</script>
<? } ?>

Why is my contact form taking me to contact.php rather than sending an email to me? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm a complete noob about web development. I have an one page HTML template that I was trying to edit as per my requirements. It has a contact form that I want people to use to send me an email. I set my email address as $to, but when I was testing the contact form, it didn't send an email to my address. Rather than that, it took me to the page contact.php and I could see all the html and php code. I'm attaching the codes for the contact form. Can anyone tell me what could possibly go wrong and how to fix this issue? Thanks in advance.
HTML Code:
<form id="contact-form" name="contact-form" method="post" action="contact.php">
<div class="row-fluid">
<p class="span6"><input id="username" name="username" type="text" tabindex="1" value="" placeholder="Name (required)"></p>
<p class="span6"><input id="email" name="email" type="text" tabindex="2" value="" placeholder="E-mail (required)"></p>
</div>
<div class="row">
<p class="span6"><textarea id="message" name="message" tabindex="4" rows="6" placeholder="Message (required)"></textarea></p>
</div>
<div class="row">
<div class="span2">
<button id="sending" type="submit" class="btn btn-embossed btn-large btn-primary" data-send="Sending...">Submit</button>
</div>
</div>
</form>
PHP Code:
(Note to the author: You can start your PHP code below:)
<?php
?>
Please click on the link to see the code. I can't post an image as I am new here. http://i.stack.imgur.com/QPHYH.jpg
It sounds like your server is not processing PHP correctly. There's nothing wrong with your HTML form, assuming contact.php is indeed the action page you want - you just need to get your server/computer to handle PHP properly. Check this answer for more info.

Categories