How to redirect after the ajax request?

Hello… using EHtml wrapper I put this instruction:

<?php echo EHtml::ajaxSubmitButton($update ? 'Almacenar' : 'Crear', '', 

                                   null, array('class'=>'boton')); ?>

The ajax submit works perfectly, but after storing the form into the database table, I need the browser to be redirected to the “admin” page. I know that it is possible since demo pages shows that it is possible to execute a JavaScript function after successful submit, so I could place a location.href there, but, those demo pages doesn’t show the PHP code to use to get the corresponding behaviour.

Any help, please?



Just replace this submit button with regular one, and redirect the user as you wish.

Ajax is used to save the cost of page reloads. In this context it does not make any sense.

thanks for replying… I had the regular submit button, but I had problems with a "cancel" button which must return to the previous page (only by executing a history.back() instruction)

If I use a regular button, and form validates incorrectly, "cancel" button stays at the form. So the question may be other: why can jformvalidate be used to validate using Ajax?. Maybe I am configuring it incorrectly.

I think about 2 possibilities.

  • Field is validated in onblur() of each field contained in the rule (using Ajax) and the submit button is enabled only if all data is correct, or…

  • when pressing submit, whole validation is perfomed using Ajax and if validation is correct, the normal submit behavior is executed.

is it possible to do one of those approaches, or both, using jformvalidate extension?



Why not store the returnUrl before the user is shown this form? That way you could provide a link to cancel.

It may be also acceptable if just guess the url the user had been visiting.