Answer the question
In order to leave comments, you need to log in
How to correctly organize the loading of html in a complex form?
There is a complex form with a user profile, jquery validation, script processing when selecting certain chuckboxes and radios. And at the bottom there is a button "Add another contact person". You press it and another exactly the same form is loaded, and the previous one remains. By clicking on "save" everything goes to the server and is saved.
Previously, I solved similar problems like this:
I made a form_chunk.tpl template on smart in which all html and js. Displayed it on the page when loading.
When you clicked on the "Add another contact person" button, ajax was sent to the server, Smarty was connected there and the html of this template was returned:
$smarty = new Smarty();
$smarty->assign('some_data', $_POST['some_data']);
$out = $smarty->fetch('form_chunk.tpl');
print json_encode(array('result' => $out));
Answer the question
In order to leave comments, you need to log in
Answer.
For such tasks, AngularJS and other frameworks have long been invented.
Also, if you use PHP frameworks like Symfony, and do not write your bike like me, the question will disappear by itself.
There, the rendering of the template (or template chunk) happens transparently. Whether it's ajax or a GET request
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question