@browniecoffee when you say 'publish button fails' how do you mean? the form doesn't submit or it submits as a draft?
My second button is not recognized in my form
Hi there,
I have problem with my form.
There are two buttons. One for draft, the other for publish
<form action="{{route('projects.updateDraft', [$project, $slug])}}" method="POST" enctype="multipart/form-data">
...
<!-- * Footer * -->
<div class="project-form__sub-footer">
<button class="project-form__button button is-rounded" type="submit" name="submit" value="draft" style="margin-bottom: 1rem;">
<span>ajouter au brouillon</span>
</button>
<button class="project-form__button project-form__button--submit button is-rounded" type="submit" name="submit" value="publish">
<span>poster mon projet !</span>
</button>
</div>
</form>
Before this worked but I don't know why not now.
there are that in my controller
/**
* Update the drafted project in database
*
* @param \Illuminate\Http\Requests\EditProject $request
* @param int $project | id of the project
* @param string $slug | slug of the project
* @param string $token | token of the drafted project
* @param \Services\ProjectService $projectService
* @return \Illuminate\Http\Response
*/
public function updateDraft(EditProject $request, $project, $slug, ProjectService $projectService)
{
...
if ($request->submit == 'draft') {
//si le status du projet est en publié
if ($project->status_id == 2) {
//je le change en brouillon
$project->update([
'status_id' => 1
]);
}
//je retourne à la dernière page
return back()->with('status', 'Projet sauvé au brouillon ! Vous pourrez le publier en cliquant sur le bouton de publication.');
}
//si l'utilisateur clique sur le bouton de publication
if ($request->submit == 'publish') {
//j'édite le status du projet en publié
$project->update([
'status_id' => 2
]);
//je redirige l'utilisateur vers le projet qu'il vient de publié
return redirect()->route('projects.show', [
'project' => $project,
'slug' => $slug
])->with('status', 'votre projet vient est à présent publié !');
}
web.php
Route::get('/projets/{project}/{slug}/modifier-mon-brouillon/{token}', 'ProjectController@draft')->name('draft');
Route::patch('/projets/{project}/{slug}/modifier-mon-brouillon', 'ProjectController@updateDraft')->name('updateDraft');
only the draft button works but publish button fails.
Can you help me please?
Thank by advance. See you.
EDIT: When I check to the network in chrome developpers tools, chrome knows what button is clicked....
I really don't understand why my form is not send so...
@browniecoffee if comment out your validation rules, your EditProject should then allow you to save.
i'd then add these rules back in 1 by 1 and this should help your find the failing rule, or where its erroring.
Please or to participate in this conversation.