mardi 8 février 2022

HTML/PHP Laravel - Select random data from input

The code is working fine at a glance. Problem is in spite of adding required term in the input form, without any input the form can be submitted.

Second thing is, submitted form showing the random value which is already set. I want when any input which matches the names in the newwelcome.blade.php file will return success message. If not matches with the input, it will show "Wrong guessed"

Here is my code: newwelcome.blade.php

<?php
function randomName() {
    $names = array(
        'Alfa',
        'BMW',
        'Opel',
        'Ford',
        'Jaguar',
        // and so on

    );
    
    return $names[rand ( 0 , count($names) -1)];
}

print randomName();

brandform.blade.php

<!doctype html>
<html>
<head>
    <title>Car Brand Game!</title>

    <!-- load bootstrap -->
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <style>
        body    { padding-bottom:40px; padding-top:40px; }
    </style>
</head>
<body class="container">

<div class="row">
    <div class="col-sm-8 col-sm-offset-2">
        <div class="page-header">
            <h1><span class="glyphicon glyphicon-flash"></span> Car Brand Game</h1>
        </div>

        <!-- FORM STARTS HERE -->
        <form method="POST" input name="feature" id="feature" action="newwelcome.blade.php" novalidate>

            <div class="form-group">
                <label for="name">Your guessed car brand:</label>
                <input type="text" id="name" class="form-control" name="name" placeholder="Which car brand was selected by the system?" required>
                
            </div>
            <button type="submit" class="btn btn-success">Submit</button>

        </form>

    </div>

</body>



Aucun commentaire:

Enregistrer un commentaire