javascript form button click counter - php

Good Morning.
I am working on button click counter using javascript function. The tricky thing is button type is submit, so page is reloaded whenever I click this button .
Here is the code which include the button.
<div class="skip">
<form method="post" >
<input type="hidden" id="skip_tinv" name="skip_tinv" value=""></input>
<button class="skip" type="submit" value="8" name="submit" onclick="skipCounter();">Skip >></button>
<?php include('includes/aftersubmit.php'); ?>
</form>
I have ten of this form in one page(which means ten of skip button in one page), and I want this "skip" button is disabled when it clicked more than three times. Do you have any idea of this?
The idea using php is also welcomed. Thank you for your help.

You can use jQuery - Prevent Default or Javascript - Prevent Default This will stop the submit button from reloading the page and you can keep track of how many times the buttons were clicked. Once that counter gets above 3 then use jQuery/javascript to hide the skip button

Related

Can I have multiple request in one form using php (laravel)

I'm building a website in which the user can create articles with multiple images.
I would like to let the users while editing the form to can delete some image that they want. So I want to have in my form the main submit button that execute the function that store all details of article but also to I have another submit button that execute the function that delete the image.
How can I do that?
Thank you so much for your attention and participation.
If I got you right, you want 1 FORM, 2 SUBMIT buttons, and based on which one you press, do a different action? It is possible to do this, but not very practical.
To do it, create 2 submit buttons with each a value. I.e.:
<input type="submit" name="mysubmit" value="delete image" />
<input type="submit" name="mysubmit" value="send the form" />
when doing this, your post/get data will contain one item names mysubmit with the value, so you know which button was pressed, and you can do an action based on this.
However, when you submit a form by pressing a submit button, you do send the whole thing to your server, and have a page refresh. I usually prefer to use Ajax for the simple operation. For example, I would remove the delete submit button and replace it a simple button. When pressed, send an Ajax call to tell the server to delete the image, and use DOM to delete the image in the browser DOM tree (usually jQuery). Note that you can also use Ajax to post the form, nicer interface, and no page refresh.

Prevent multiple submissions

I have a page that sends data to itself, i.e.using PHP_SELF.
Upon page refresh, i.e. when the page reloads, I place two buttons - Refresh Again, where I
send data using again using PHP_SELF. - An alert box pops up asking for confirmation, that usually occurs when date is sent again to a page.
The purpose of the second button - Reload without sending data, must reload the page.
Without the above pop up box appearing, i.e. without data being sent.
Is there a way to flush out data before it is sent again to the
server or to a page?
I send data via $_GET.
I check whether I receive any data as follows:
if(isset($_GET['getVariable']))
/* I place the buttons here, in a form, the action parameter of which points to the same page, i.e. `PHP_SELF`
You could make the refresh without submitting a new form:
<form name="refresh" action="" method="post">
<input type="submit" value="Refresh without submitting" />
</form>
Or use JavaScript to refresh on the current button.
<input type="button" value="Refresh without submitting" onclick="location.reload();" />
Also, use action="" instead of PHP_SELF.

Button INPUT that saves data and links at the same time

I'm doing a questionnaire (form) and I need to put a submit button that does two things:
Be a button type INPUT (because I need to use this kind of button on my PHP code, I've if(#$_POST['Next']) for save the dates of the form in my DB).
That this button will have a link for go to the next screen of the questionnaire. I tried with
<a href="demo2.html" target="_blank">
<input class="buttonNext" name="submit" type="submit" value="NEXT &#8592">
</a>
This code doesn't work, but with IE browser, on the page appears a circle next to my button that is the link. So the button doesn't work; it only saves the data, but doesn't link to the next page.
How can I solve it?
The form's action determines the URL where the form is sent, and this is just good for you (it is sent to the PHP that processes this step). It can save the data and/or return the form again to show validation errors. Once you decide to go to the next step, you can redirect the user to that url.
use if(isset($_POST['Next'])){ instead of #

Two submit buttons with different actions?

I have a form having login button and registeration button.
Registeration Button:
This button should deal two text boxes name and email:
<div id="regisbutton" class="regisbutton1">
<input type="submit" value="Register" class="regisbutton" name="registerSubmit"/>
</div>
Login Button:
This button should also consider only two textboxes username and password:
<div id="loginbutton" class="loginbuttonclass">
<input type="submit" value="Login" class="loginbutton" name="loginSubmit" />
</div>
Problem is I put validation JavaScript which runs automatically and before form action it checks if text boxes are empty or not. But I want to run this JavaScript for registeration textboxes only not for login textboxes.
I have used submit type for both buttons.
You are using two different actions, so you need to different forms!
Without the <form> tag, the input button is quite useless anyway! Also don't rely on javascript only, validate the form with php as well in case js is turned off by the client!
So just wrap each submit button in a different form with a different action/validation and you're done!
If you want validation to only run if you click register, you shouldnt link the validation function to the form submit event but to the register button onclick event.

HTML Forms: How do I add multiple buttons that pass different values?

I have a script that allows the posting of news. I want to be able to create a 'save as draft' button next to the 'publish' button. How can I allow the 'save as draft' button to pass a value to the back end?
I just need a simple 1 or 0 depending on which button was pressed, I'm using php by the way.
<input type="submit" name="saveasdraft" value="Save as Draft">
<input type="submit" name="save" value="Save">
And then you can detect which button was pressed at the backend by their name. The one that was pressed will be present in the submitted form fields. The others won't be.
You can use multiple form elements.

Categories