A
A
Anton2016-11-10 10:04:35
PHP
Anton, 2016-11-10 10:04:35

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));


We work together: mysql, php, jquery, html5, css3

Now I am developing a system together with one developer, and during the discussion, we had questions:
1. Is such an approach competent?
2. How do you solve such problems in your projects?
3. How are such tasks solved in large projects like Google, Yandex, VK?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2017-03-29
@fattan

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 question

Ask a Question

731 491 924 answers to any question