Enable fields from the previous field

1

I need to make a form that, in order to enable a field, it is mandatory to fill in an earlier field.

There will be a pagination between one question and another (next or previous).

Can you do this in Ajax?

I'm using PHP and I think this can be done with AJAX or JQuery , but I do not know how to do this.     

asked by anonymous 21.06.2014 / 19:19

2 answers

1

I made an example in JSFiddle here , I used > Bootstrap and jQuery , I have numbered the step with the 'date-step' attribute, and the field (s) ) required the 'required' attribute;

  • JQuery

So the 'prev' and 'next' functions related to 'data-next' and 'data-prev' (attribute);

Validation and call in the 'next' function, passing the active step and validating.

Validation should be done in PHP!

    
27.07.2014 / 03:38
0

With or without Bootstrap, what I usually do with this kind of forms is to do everything on the same page, using only PHP.

And with onChange change the action of the form.

<form action="">
...
   //mudando de página
   <input name="input1" onChange="this.form.action='novaPagina.php'">

   //se pretender ficar na mesma página
   <input name="input2">

   <?php
   if (isset($_POST['input2']))
   {
       //verificação que pretender, como por exemplo adicionar um campo:
       echo "<input name='input3'>";
       ...
       //ou preencher um campo 
   }
   ?>
...
</form>

If I do not get clarified tomorrow, I'll improve the answer.

    
27.06.2014 / 02:10