How to change the name of the button if user has registered - LARAVEL?

Asked

Viewed 139 times

-1

Good evening, I would like to put a notice on the button if user has made such registration in my case have renewed, user enters the card and note that already made the registration the name of the button changes and is written "subscribed"...

--- Controller store that saves, and lists data and sends the data to the form

public function listardados(){
    $matricula = Matricula::where('user_id', Auth::id())->get();

    //dd($matricula);
    return view('dashboard.renovacao.teste', compact( 'matricula'));
}

public function store(RenovacaoRequest $request){


    $user = Auth()->user();

    $dados = $request->get('rematricula');

    foreach ($dados as $key => $dado) {

        Renovacao::create($dado);
    }

    return view('dashboard.renovacao.confirmacao', compact ('renovacao'));
}

--FORM

@extends('layouts.app') @section('content')

<div class="container">
<div class="row">

    <form class="form-horizontal " id="regForm" action="{{route('renovacao.store')}}" method="POST">
        <div class="card-panel white">
            <h4 class="center">Solicitar Renovação</h4>
            <div class="row"></div>
            {{ csrf_field()}}

            <div class="row">
                @if($matricula->count())
                    <right>
                        <a>**Dados Cadastrados**</a>
                    </right>
                    <div class="row"></div>
                    <div class="row"></div>
                    @foreach($matricula as $matric)

                        <div class="row">
                            <div class="col s6 m6">
                            <div class="input-field {{$errors->has('') ? 'has-error' : ''}} ">
                                <label for="produto">Nome do Pai:</label>
                                <input type="text" class="form-control" name="rematricula[{{ $loop->index}}][nomerespo]" value="{{ $matric->nomedopai }}">
                            </div>
                            </div>

                            <div class="col s6 m6">
                            <div class="input-field {{$errors->has('') ? 'has-error' : ''}} ">
                                <label for="produto">Nome do Aluno(a):</label>
                                <input type="text" class="form-control" name="rematricula[{{ $loop->index}}][nomealuno]" value="{{ $matric->nomealuno }}">
                            </div>
                            </div>

                        </div>

                    @endforeach
                    <div class="col s12 m6">
                        <div class="row"></div>
                        <div class="row"></div>
                        <div class="row">
                            <div>
                                <div class="card-panel white ">
                                    <b class="black-text">AVISO? </b></br></br>
                                    <span>• Mensagem de Aviso </span></br></br>

                                </div>
                            </div>
                        </div>
                        <div class="row">
                        </div>
                    </div>


                    <div class = "row">
                        <div class="col s12">

                            <a title="Voltar Para Página Principal" class="btn orange darken-4 btn-info left " href="/admin">Voltar
                                <i class="material-icons left">arrow_back_ios</i>
                            </a>

                            <button type="submit" class="btn orange darken-4 btn-info right">Confirmar
                                <i class="material-icons left">save</i>
                            </button>
                        </div>
                    </div>
                @else
                    <div class="row"></div>
                    <div class="row"></div>
                    <p> Desculpe! Página Indisponivel, Você não tem cadastro nessa instituição, Procure a secretaria e faça sua Matrícula </p>
                    <div class="row"></div>
                    <div class="row"></div>
                    <div class="row"></div>
                    <div class="row"></div>
                    <a title="Voltar Para Página Principal" class="btn orange darken-4 btn-info left " href="/admin">Voltar
                                <i class="material-icons left">arrow_back_ios</i>
                    </a>
                @endif



            </div>
        </div>    
    </form>
</div>

@endsection

  • JAVASCRIPT or PHP ?

  • PHP even because Laravel is only a framework

  • "only after Reload", as well men ?

  • when the page reloads.

  • humm understood, this is how I still do n mexo with javascript to do everything without having to load the page :)

  • How can I treat the problem ?

  • ideal is you say which button you want to change, wherever it appears. only with php I have no merit other than inside echo.

  • I’ll make 2 example codes for you to see

  • Blz, you can change the button to confirm where you are going to change "to registered" the location may be the same place you were

  • Blz mano ......

  • I saw on the site and I registered a test this is the way I wanted, top

  • With message on button

  • You have sample code ?

  • Descupe. I didn’t see it when I said I had accessed it. it’s javascript. more is very simple. and can be reused in many codes at the same time.

  • Send it to me to test it here

  • so you want javascript anyway ?

  • Let’s see if it funfar here no problem rsrs

Show 12 more comments

1 answer

0


add that to your javascript code file,

$(document).ready(function () {
	//escolhendo o formulario pelo ID
$('#id_do_formulario').submit(function(e) {
	//evitando que a pagina seja recarregada
	e.preventDefault();
	//evita que o efeito caia sobre os objetos parentes
	e.stopPropagation();
		// iniciando requisição
    $.ajax({
    	//define com GET OU POST de acordo com seu formulario.
        type: 'POST',
        //pégando o link de processamento
        url: $(this).attr('action'),
        //pegando os campos do formulario
        data: $(this).serialize(),
        //escolhendo o tipo de dados recebido
        dataType: 'html',
        //Definindo resposta no cado de sucesso.
        success: function(data) {
        	//ções caso a o processamento tenha dado certo
			$('#id_do_formulario').prepend(data);//adicionando resposta no formulario
			$('#id_button_submit').text('Novo texto do button');//mudando texto do buttan
			
        }
    })
    return false;
});
});
> e isso, você adiciona no final do arquivo do formulario.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

  • edit the fields I marked the ID and be Felix.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.