<form id="myForm" action="/save-data" method="post">
<!-- ...поля... -->
<button type="submit">Отправить</button>
</form>
<form id="myForm" action="/save-data" method="post">
<input type="hidden" name="form_token" value="уникальное_значение_12345">
<!-- ...другие поля... -->
<button type="submit">Отправить</button>
</form>
window.addEventListener('pageshow', function(event) {
// event.persisted бывает true, когда страница загружается из bfcache
if (event.persisted) {
const form = document.getElementById('myForm');
if (form) {
form.reset(); // Сбрасываем все поля формы
const button = form.querySelector('button[type="submit"]');
button.disabled = false; // Убедимся, что кнопка снова активна
console.log('Страница восстановлена из кэша. Форма сброшена.');
}
}
});
<?php if ($isSent): ?>
<p>Email sent successfully!</p>
<?php else: ?>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<label for="subject">Тема письма : </label> <br>
<input type="text" name="subject" size="30"> <br>
<label for="elvismail">Содержание письма : </label> <br>
<textarea name="elvismail" id="" cols="30" rows="10"></textarea> <br>
<input type="submit" name="submit">
</form>
<?php endif; ?>
все вычисления всегда выносить в отдельные функции, а эти функции всегда типизировать по-максимуму.
<?php
$sum = 400;
// Было
$all = $sum * (55 / 100);
var_dump($all); // На выходе float(220.00000000000003)
// Стало
$all2 = calculateAll($sum);
var_dump($all2); // На выходе int(220)
function calculateAll(int $sum): int
{
return $sum * (55 / 100);
}
float(220.00000000000003)
PHP Deprecated: Implicit conversion from float 220.00000000000003 to int loses precision in /Users/vitiok78/Downloads/float.php on line 12
Deprecated: Implicit conversion from float 220.00000000000003 to int loses precision in /Users/vitiok78/Downloads/float.php on line 12
int(220)
https://example.com/page // окна нет
https://example.com/page#modal1 // окно открыто
- var html = e.target.parentNode.querySelector('.firmware-window');
+ var html = e.target.parentNode.querySelector('.firmware-window').cloneNode(true);
$('.modal-wrapper').attr('class', 'modal-wrapper').html(html);
html.classList.remove('hiden');
<?php
function getArrayValueByPath($array, $path, $separator = "/")
{
// Разбиваем путь на ключи
$keys = explode($separator, $path);
// Текущий уровень массива - начинаем с корня
$current = $array;
foreach ($keys as $key) {
// Если ключа нет в массиве, то выбрасываем исключение
if (!isset($current[$key])) {
throw new \Exception(
"Ключ $key не найден в массиве по адресу '$path'"
);
}
// Переходим к следующему уровню вложенности массива
$current = $current[$key];
}
// Возвращаем значение по заданному пути
return $current;
}
// Использование функции:
$arr = [
"k1" => [
"k2" => [
"k3" => [
"k4" => "v",
],
],
],
];
$result = getArrayValueByPath($arr, "k1/k2/k3");
var_dump($result);
/** Результат выполнения:
array(1) {
["k4"]=>
string(1) "v"
}
*/
Объясни принципы SOLID. Используй примеры на PHP. Объясняй как десятилетнему ребёнку
// SendMessageParams - Represents parameters of sendMessage method.
type SendMessageParams struct {
// BusinessConnectionID - Optional. Unique identifier of the business connection on behalf of which the
// message will be sent
BusinessConnectionID string `json:"business_connection_id,omitempty"`
// ChatID - Unique identifier for the target chat or username of the target channel (in the format
// @channel_username)
ChatID ChatID `json:"chat_id"`
// MessageThreadID - Optional. Unique identifier for the target message thread (topic) of the forum; for
// forum supergroups only
MessageThreadID int `json:"message_thread_id,omitempty"`
// Text - Text of the message to be sent, 1-4096 characters after entities parsing
Text string `json:"text"`
// ParseMode - Optional. Mode for parsing entities in the message text. See formatting options
// (https://core.telegram.org/bots/api#formatting-options) for more details.
ParseMode string `json:"parse_mode,omitempty"`
// Entities - Optional. A JSON-serialized list of special entities that appear in message text, which can be
// specified instead of parse_mode
Entities []MessageEntity `json:"entities,omitempty"`
// LinkPreviewOptions - Optional. Link preview generation options for the message
LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
// DisableNotification - Optional. Sends the message silently
// (https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound.
DisableNotification bool `json:"disable_notification,omitempty"`
// ProtectContent - Optional. Protects the contents of the sent message from forwarding and saving
ProtectContent bool `json:"protect_content,omitempty"`
// MessageEffectID - Optional. Unique identifier of the message effect to be added to the message; for
// private chats only
MessageEffectID string `json:"message_effect_id,omitempty"`
// ReplyParameters - Optional. Description of the message to reply to
ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"`
// ReplyMarkup - Optional. Additional interface options. A JSON-serialized object for an inline keyboard
// (https://core.telegram.org/bots/features#inline-keyboards), custom reply keyboard
// (https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a
// reply from the user
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
}
// ReplyParameters - Describes reply parameters for the message that is being sent.
type ReplyParameters struct {
// MessageID - Identifier of the message that will be replied to in the current chat, or in the chat chat_id
// if it is specified
MessageID int `json:"message_id"`
// ChatID - Optional. If the message to be replied to is from a different chat, unique identifier for the
// chat or username of the channel (in the format @channel_username). Not supported for messages sent on behalf
// of a business account.
ChatID ChatID `json:"chat_id,omitempty"`
// AllowSendingWithoutReply - Optional. Pass True if the message should be sent even if the specified
// message to be replied to is not found. Always False for replies in another chat or forum topic. Always True
// for messages sent on behalf of a business account.
AllowSendingWithoutReply bool `json:"allow_sending_without_reply,omitempty"`
// Quote - Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing.
// The quote must be an exact substring of the message to be replied to, including bold, italic, underline,
// strikethrough, spoiler, and custom_emoji entities. The message will fail to send if the quote isn't found in
// the original message.
Quote string `json:"quote,omitempty"`
// QuoteParseMode - Optional. Mode for parsing entities in the quote. See formatting options
// (https://core.telegram.org/bots/api#formatting-options) for more details.
QuoteParseMode string `json:"quote_parse_mode,omitempty"`
// QuoteEntities - Optional. A JSON-serialized list of special entities that appear in the quote. It can be
// specified instead of quote_parse_mode.
QuoteEntities []MessageEntity `json:"quote_entities,omitempty"`
// QuotePosition - Optional. Position of the quote in the original message in UTF-16 code units
QuotePosition int `json:"quote_position,omitempty"`
}
id, ticket, reply_message := db.GetTicketAndMessage(message.ReplyToMessage.MessageID, user.ID)
if ticket == nil {
_, _ = bot.SendMessage(&telego.SendMessageParams{
ChatID: telego.ChatID{ID: message.Chat.ID},
Text: "This ticket or message does not exist.",
ReplyParameters: &telego.ReplyParameters{
MessageID: message.MessageID
},
ParseMode: "HTML",
})
return
}