У меня такая же проблема. Apache не загружает php-файлы с определенного веб-сайта, просто скачал его. Я прочитал этот пост и ответы, и я видел, что у меня есть эта строка в последнем месте файла .htaccess:
AddHandler x-mapp-php5.5 .php
Я прокомментировал это, и все работает нормально.
Спасибо всем !!!
Кажется, что проблема со всеми остальными ответами до сих пор заключается в том, что когда кнопка отправки отключена, это приводит к тому, что пара данных name
- value
, связанная с ней, не будет отправлена, поскольку кнопка отключена перед публикацией данных. Тем не менее, кнопки submit
обычно не используются для передачи данных в любом случае, поэтому одним из решений этой проблемы является просто связать данные с отдельным скрытым элементом input
.
HTML:
<form id="form" target="_blank" method="post" action="page2.php">
<input type="hidden" name="btn" value="btn"></input>
<input id="submit-button" type="submit" value="btn">
<br />
</form>
Обратите внимание, что я добавил id
s в форму и кнопку отправки для выбора в JavaScript.
JavaScript:
// Get the form and the submit button.
var form = document.getElementById('form');
var submitButton = document.getElementById('submit-button');
// Disables the submit button.
function disableSubmitButton() {
submitButton.setAttribute('disabled', '')
}
// Disable the submit button when the form is submitted, with fallback for IE 5-8.
if (form.addEventListener) {
form.addEventListener('submit', disableSubmitButton, false);
} else {
form.attachEvent('onsubmit', disableSubmitButton);
}
Если у вас было два разных представления кнопки, вы также можете передать другое значение на страницу действия в зависимости от того, какая кнопка была нажата, установив значение скрытого элемента input
, на основе которого был нажат:
HTML:
<form id="form" target="_blank" method="post" action="page2.php">
<input id="hidden-input" type="hidden" name="button-pressed" value=""></input>
<input id="submit-button-1" type="submit" value="Submit Button 1">
<input id="submit-button-2" type="submit" value="Submit Button 2">
<br />
</form>
JavaScript:
// Get the form and the hidden input.
var form = document.getElementById('form');
var hiddenInput = document.getElementById('hidden-input');
// Set the value of the hidden input depending on which button was pressed.
function setHiddenInputValue(event) {
// Get the id of the button that was pressed.
pressedButtonId = event.target.id;
// Set the value of the hidden input element to be the same as the id of the pressed button.
hiddenInput.setAttribute('value', pressedButtonId);
// Disables the submit button that was pressed.
function disableSubmitButton(event) {
event.target.setAttribute('disabled', '')
}
// Disable the submit button when the form is submitted, with fallback for IE 5-8.
if (form.addEventListener) {
form.addEventListener('submit', function(event) {
// Event object fallback for IE 5-8.
if (!event) {
event = window.event;
}
setHiddenInputValue(event);
disableSubmitButton(event);
}, false);
} else {
form.attachEvent('onsubmit', function(event) {
// Event object fallback for IE 5-8.
if (!event) {
event = window.event;
}
setHiddenInputValue(event);
disableSubmitButton(event);
});
}
Вы можете сделать это с помощью jQuery. Вам нужно включить скрипт jQuery. И напишите свой собственный код для управления событиями
<form target="_blank" method="post" action="page2.php">
<?
echo '<input type="submit" value="btn" name="btn" id="submitBtn"><br>';
?>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
$(document).ready(function() {
$("#submitBtn").click(function(){
$("input[type=submit]").attr('disabled','disabled'); // disable the button
// $("input[type=submit]").removeAttr('disabled') You can enable the button from this code
});
});
Вы можете отключить при отправке формы: -
$('form#id').submit(function(){
$(this).find(':input[type=submit]').prop('disabled', true);
});
$('form').submit(function(){
$(this).find(':input[type=submit]').attr('disabled','disabled');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form target="_blank" method="post" action="page2.php">
<input type="submit" value="btn" name="btn">
</form>