DEV Community

Cover image for PHP form 71: complete upload
Falah Al Fitri
Falah Al Fitri

Posted on • Edited on

PHP form 71: complete upload


Happy Coding

index.php

    <form method="post" action="process.php" enctype="multipart/form-data" >

        Firstname: <input type="text" name="firstname" />
        <br />

        Lastname: <input type="text" name="lastname" />
        <br />

        Description: <textarea name="description" rows="10" cols="50"></textarea>
        <br />

        Gender:
        <input type="radio" name="gender" value="male" checked /> Male
        <input type="radio" name="gender" value="female" /> Female
        <br />

        Programming Language (single):
        <select name="language" >
            <option value="c" >C</option>
            <option value="c++" >C++</option>
            <option value="java" >Java</option>
            <option value="javascript" >Javascript</option>
            <option value="php" selected >PHP</option>
        </select>
        <br />

        Programming Languages (multiple):
        <select name="languages[]" multiple >
            <option value="c" >C</option>
            <option value="c++" >C++</option>
            <option value="java" >Java</option>
            <option value="javascript" selected >Javascript</option>
            <option value="php" selected >PHP</option>
        </select>
        <br />

        Hobbies (single): <input type="checkbox" name="hobby" value="studying" /> Studying
        <br />

        Hobbies (multiple):
        <input type="checkbox" name="hobbies[]" value="studying" /> Studying
        <input type="checkbox" name="hobbies[]" value="reading" checked  /> Reading
        <input type="checkbox" name="hobbies[]" value="writing" /> Writing
        <input type="checkbox" name="hobbies[]" value="sleeping" checked /> Sleeping
        <br />

        File Upload: <input type="file" name="upload" /><br />
        Preview: <img src="#" /> <br />

        <hr />

        <input type="submit" name="submit" value="Submit" />

    </form>
Enter fullscreen mode Exit fullscreen mode

process.php

$data = array(
    "post"  => $_POST,
    "files" => $_FILES
);

echo "<pre>";

// echo json_encode($data);

var_dump($data);
Enter fullscreen mode Exit fullscreen mode

Output


Demo repl.it


Thank for reading :)

Top comments (0)