A
A
Alexander2014-04-09 18:46:36
MySQL
Alexander, 2014-04-09 18:46:36

How can a div be saved?

The question is rather crooked.
There is a button that adds an unlimited number of divs

$(function(){
  var count = 0;
  $('#append').click(function(){
    $('#parent').append('<div style="width:840px;" id="first'+count+'"> тут содержимое дива </div>');
    count++;
  });
});

Initially, this diva does not exist. This div is a piece of the form
What is the task before me - you need to create this div, there is some input inside it, the user writes something there.
Adds, if necessary, one more such div and also writes something.
How can I save all this after submitting the form, so that later on the edit page I can edit these inputs and have these divs in the same form and order in which they were created? Maybe somehow save everything in the database? But something is doubtful...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Morozov, 2014-04-09
@ghost1k

it is natural to save in the database
to do it like this:

<form ...>
<div ...><input name="values[]" ...></div>
</form>

added another one and now it will be like this
<form ...>
<div ...><input name="values[]" ...></div>
<div ...><input name="values[]" ...></div>
</form>

<?php

//скрипт в который происходит submit
...

$values = implode(";", $_POST["values"]);

//сохранить в базу строку $values

?>

//скрипт отображения form-ы

<form ...>
<?php

//достать $values из базы

$arr = explode(";", $values);

for ($arr as $value)
{
echo "<div><input name=\"values[]\" value=\"$value\" /></div>";
}

?>
<imput type="submit" />
</form>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question