This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

johndoegrip62221
johndoegrip62221

HI all, I have a problem when upload a file from frontend, I am using a model to save my file. https://octobercms.com/docs/database/model#basic-inserts $flight = new Flight; $flight->name = 'Sydney to Canberra'; $flight->save();

but I cant get my file from frontend. I have followed instruction from this tutorial https://www.youtube.com/watch?v=KABsGjyhhVM&ab_channel=WatchandLearn

But nothing happened, it doesn't show any error but cannot saved into db, I am using postgresql. FYI I am using DB::Insert too

Thank you

mjauvin
mjauvin

Make sure you are using build 1.0.471 of October CMS

johndoegrip62221
johndoegrip62221

mjauvin said:

Make sure you are using build 1.0.471 of October CMS

HI mjauvin, I already use that version of builder. Just to be clear, below is my code :

<form method="POST" action=" { (url) bla bla}" accept-charset="UTF-8" enctype="multipart/form-data" id="example" class="something">

<input type="hidden" name="handler" value="onSave">

{{ form_token() }}
{{ form_sessionKey() }}

<div class="tab-content py-4" id="second-menu">
    <div class="container">
        <div class="content-letter tab">
            <p class="title-letter">Please Fill This Form</p>

        <div class="content-letter tab">
            <div class="mt-3">
                <div class="form-group row">
                    <div class="col-12">
                        <label class="text-dark font-weight-bold">Nama</label>
                        <input type="text" class="form-control" placeholder="Name" name="name"
                            id="name" required>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <label class="text-dark font-weight-bold">Phone</label>
                        <input type="number" class="form-control" placeholder="Phone" name="phone"
                            id="phone" required>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-12">
                        <label class="text-dark font-weight-bold">Signature</label>
                        <div class="row">
                            <div class="col-9 col-md-10">
                                <div class="custom-file">
                                    <input type="file" id="signature" class="custom-file input-file"
                                        name="signature" accept="image/x-png,image/gif,image/jpeg">
                                    <label id="label-sign" for="sign"
                                        class="custom-file-label label-files">Upload Signature</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <button
            id="btn-okay"
            type="submit"
            data-request="onSave"
            data-hotkey="ctrl+s, cmd+s"
            data-load-indicator="Creating New..."
            class="btn btn-primary">
            Join
        </button>
    </div>
</div>
</form>

and this is my function :

function onSave() {
$expert= new Expert();
$model = new \Models\Expert;

$expert->name = Input::get('name');
$expert->phone = Input::get('phone');
$expert->sign= Input::file('signature');

$expert->save();
return Redirect::back;

//or even this one
/*$nama = Input::get('name');
$phone = Input::get('phone');
$sign = Input::file('signature');

DB::table('expert')->insert([
    'name' => $name,
    'phone' => $phone,
    'sign' => $sign
]);
return Redirect::back;*/
}

and not to forget I did a model relation too:

public $attachOne = [
    'signature' => 'System\Models\File'
];

what's wrong with my code. I already follow all of instruction

Last updated

mjauvin
mjauvin

try adding data-request-files to your <form> tag

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.