Можно ли выполнить несколько действий в формах, используя только одну кнопку отправки? - PullRequest
0 голосов
/ 05 февраля 2020

См. Вопрос - я пробовал это:

echo "<form action='index.php' method='post'>   
Use the previous input of participants: <input type='radio' name='participants[]'value='$participants[0]'> 
OR <br>
<form action='index.html' method='post'>
Use a different input of participants: <input type='radio' name='participants[]' value='0'>
<input type='submit' value='send' name='send'> </form> <br>";

Оба переключателя приводят меня к индексированию. php, когда я хочу иметь возможность go индексировать. html на случай, если я нажму на второй переключатель.

1 Ответ

1 голос
/ 05 февраля 2020

Вы можете решить это, используя JQuery

<form action='index.php' method='post'>   
    Use the previous input of participants: 
    <input type='radio' name='participants[]' value='$participants[0]'> 
    <br/>OR <br> 
    Use a different input of participants: 
    <input type='radio' name='participants[]' value='0'>
    <input type='submit' value='send' name='send'> 
</form> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    var form  = $('form');
    var input = $('input[type=radio]');
    input.on('click', function() { 
        if ($(this).val()==0) { 
            form.prop('action', 'index.html');
        } else {  
            form.prop('action', 'index.php');
        } 
    }); 
});
</script>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...