Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Sweetalert 2 - Post Variable from form AND Sweetalert to PHP?

I have the following code. I need the variable "$computerID" from the form and the variable "hardwareComputerName". I tested some things, but nothing worked. The variable "$computerID" is no problem.

The form:

<form id="computerRenameForm" action="computerRename" method="post">
    <input type="hidden" name="rename" value="">
    <input type="hidden" name="computerID" value="<?= htmlspecialchars($computer->id) ?>">
</form>
<button onclick="confirmComputerRename()"><i class="bi bi-trash-fill"></i> Umbenennen</button>
                    
<script>
    function confirmComputerRename()
    {
    (async () => {
        const { value: hardwareComputerName } = await Swal.fire({
            html: "Zum Umbenennen muss der Computer online sein.<br>Das Gerät wird neu gestartet.",
            icon: 'warning',
            input: 'text',
            inputAttributes: {maxlength: 15},
            showCancelButton: true,
            confirmButtonText: 'OK',
            confirmButtonColor: '#ff0000',
            cancelButtonText: 'Abbrechen',
            reverseButtons: false
        })
    
        if (hardwareComputerName) {
            document.getElementById("computerRenameForm").submit();
        }
    })()
}
</script>

The Controller:

<?php
if (isset($_POST['rename'])) {
    $computerID = $_POST['computerID'];
    $hardwareComputerName = $_POST['hardwareComputerName'];

    var_dump($computerID)."<br>"; // Works
    var_dump($hardwareComputerName); // Works not
}
?>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!