0

I have a form in Html and after sending the data, I have a task to leave the information entered by the user, and not to clean the form. Form exemple:

<form method="get">
    <input type="search" id="search" name="req" autocomplete="off" spellcheck="false" role="combobox"
           placeholder="write here" aria-live="polite"><br>
<div class="form_radio_btn">
    <input id="radio-1" type="radio" name="radio" value="first" checked>
    <label for="radio-1">first</label>
</div>
<div class="form_radio_btn">
    <input id="radio-2" type="radio" name="radio" value="Second">
    <label for="radio-2">second</label>
</div>
</form>

Please suggest

ripidipi
  • 1
  • 4
  • And form must be submitted via `POST` method to receive information in back-end – Justinas Jul 26 '22 at 11:50
  • Thanks but prefer use this method here and this solution is not quite suitable because I would like to refrain from using PHP since the project does not use it – ripidipi Jul 26 '22 at 11:56
  • Front end does not care what back-end is, so sending data via Ajax has nothing to do with PHP – Justinas Jul 26 '22 at 12:11
  • OK I understend that here I will use PHP as it's better solution then js – ripidipi Jul 26 '22 at 12:24

2 Answers2

1

Call event.preventDefault() and make an http request using js

Aziz Hakberdiev
  • 180
  • 2
  • 9
0
<form method="get">
    <input type="search" id="search" name="req" autocomplete="off" spellcheck="false" role="combobox"
           placeholder="write here" aria-live="polite" value="<?php if(isset($_REQUEST['req'])){ echo $_REQUEST['req'];}?>"><br>
<div class="form_radio_btn">
    <input id="radio-1" type="radio" name="radio" value="first" <?php if(isset($_REQUEST['radio']) && $_REQUEST['radio']=='first'){ echo 'checked';}?>>
    <label for="radio-1">first</label>
</div>
<div class="form_radio_btn">
    <input id="radio-2" type="radio" name="radio" value="Second"  <?php if(isset($_REQUEST['radio']) && $_REQUEST['radio']=='Second'){ echo 'checked';}?>>
    <label for="radio-2">second</label>
</div>
</form>

Or use Ajax

Shozab javeed
  • 232
  • 2
  • 11