Form within Form

Asked

Viewed 4,533 times

0

Good morning!

I already checked the link, Form within Form, but that’s not what I’m looking for.

I need to know if one form inside the other with two buttons and two distinct actions works.

Example:

<form type="post" action="dados_cadastrais.php">

    <form type="post" action="negocicao.php">
         <input type="text" value="nome" />
         <input type="submit" value="Enviar">
    </form>

    <input type="text" value="Parcela">
    <input type="submit" value="Salvar">
</form>

Actual code of the project:

               <form method="post" action="<?= base_url()?>admin/credores/adicionar" id="form_credor_adicionar">
                    <div class="modal-body" style="padding-bottom: 0px;"> <!--padding 0px -->
                        <div class="row">
                            <div class="form-group col-sm-4">
                                <label for="cnpj">CNPJ</label>
                                <input type="text" id="cnpj" name="cnpj" class="form-control" autocomplete="off" placeholder="000.000.000-00" value="<?php echo set_value('cnpj'); ?>" >
                            </div>
                            <div class="form-group col-sm-6">
                                <label for="nome">Nome</label>
                                <input type="text" id="nome" name="nome" class="firstname form-control" autocomplete="off" onkeyup="maiuscula('.firstname')" placeholder="Informe o nome do devedor" value="<?php echo set_value('nome'); ?>" >                             
                            </div>
                            <div class="form-group col-sm-2">
                                <label for="genero" class="control-label">Ativo</label>
                                <select id="genero" name="genero" class="form-control">
                                    <option value="" selected="selected">Selecione</option>
                                    <option value="1">Sim</option>
                                    <option value="0">Não</option>
                                </select>
                            </div>
                            <div class="form-group col-sm-12" style="margin-bottom: 0px;"> <!--margem 0px -->
                                <div class="card card-border nav-tabs-custom">
                                    <ul class="nav nav-tabs" id="myTab">
                                        <li class="active"><a href="#dados_cadastrais" data-toggle="tab" aria-expanded="true"><i class="fa fa-user" style="color: #A4BE40"></i> Dados Cadastrais</a></li>
                                        <li class=""><a href="#tabela_negociacao" data-toggle="tab" aria-expanded="false" ><i class="fa fa-map-marker" style="color: #E9573F"></i> Tabela de Negociação</a></li>
                                    </ul>
                                    <div class="tab-content" style="">
                                        <?php include 'include/tab_adicionar_dados_cadastrais.php';?>
                                        <?php include 'include/tab_adicionar_tabela_negociacao.php';?>
                                    </div>
                                </div>
                            </div>      
                        </div>
                    </div>
                    <div class="modal-footer clearfix">                         
                        <button type="submit" class="btn btn-primary btn-flat pull-left"><i class="fa fa-save"></i> Salvar</button>
                        <button type="button" class="btn btn-default btn-flat" onclick="limpar_campos(this.form)"><i class="fa fa-refresh"></i> Limpar</button>
                        <button type="button" class="btn btn-default btn-flat" data-dismiss="modal"><i class="fa fa-times"></i> Cancelar</button>                           
                    </div>
                </form>

inserir a descrição da imagem aqui

  • 2

    what is the need for this?

  • I have a modal that contains two tabs, Where the first tab must send registration data. And the second tab, sends negotiation data. Both tabs call different controllers and send data to right tables. Where the two tabs are called via include and are between a form.

  • I still don’t understand the need for a form within another

  • It does not work, it will only work < input type="Submit" value="Send" > in the action data_cadastrais.php

  • See the code update. <? php include 'include/tab_addir_table.php';? >, this part is another form

  • No, it doesn’t work. Elements form cannot be nested. See here. If the forms use different controllers and send to different tables, it makes no sense that they are in the same form.

  • Nothing has changed, see http://kithomepage.com/sos/dois-forms.htm only the button of the form included with the action of the first form

  • @Andersoncarloswoss, as soon as I separate the two form, the page ran away from the layout, there is some other way to do it ?

  • Yes, adjust your layout accordingly. Using one form within another will be gambiarra. Don’t do this.

  • Thank you all!

  • To not escape the layout, you will have to work a little. Put the second form inside a div and outside the first form. With css you are able to position exactly in the desired location. I made a model, :) , see http://kithomepage.com/sos/dois-forms.htm both "save" and "send" work.

  • @Leocaracciolo, I even put an example of images, to see how I’m doing! In this line: <div class="tab-content" style=""> <?php include 'include/tab_addition_data_cadastrais.php';? > <?php include 'include/tab_address_table.php';? > </div> about tab_addition_dates_cadastrais.php, all right, because you compose the same form, but tab_addition_table, is part of another form. I wanted to keep this layout

  • So, this is what I told you in the previous comment, you’ll have to put the div class="tab-content with form2 width and height. Put form2 in a div id="form2" outside of Form1. With css position the div with id=form2 on top of the div class="tab-content. That’s what I did in my model. Check the source code there.

  • Maybe changing your question to how to position with css a div that contains a form within a div on the page ....

Show 9 more comments

1 answer

7


Not only will it not work, it will make your HTML invalid. See tag description MDN form

Permitted: Flow content, but with no contained <form> Elements.

You can also use the W3C validator

Even so, if you add one form inside the other, the Ubmit actions (be button or input) will submit the form external (the parent of all) sending all inputs, even if it is in one form intern.

  • Dow was due to reply address the same as the comments.

  • @Leocaracciolo comments are not answers. Avoid commenting votes, only constructive comments, according to OS rules.

  • @Gabrielheming the first part is correct, a question needs to have an answer. Ideally it should have been posted by someone who solved in the comments. But commenting on the reason of the vote is something good, if the person wants. This way we know it was a wrong vote, after all it seems that the answer is right and this is what counts. Maybe Leo rethinks the vote.

  • @bigown thanks for the clarification. I expressed myself in the wrong way.

  • because then, the answer was given after those comments stating that it is not possible even with an online example and Gabriel could also put this answer in the comments like Anderson. But reflecting the comment of @bigown I think this is right and I will reconsider, after all Anderson and I had a chance to respond before and if we did not have to give the due credit

Browser other questions tagged

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