1

creating form using javascript

    var mapForm = document.createElement("form");
    mapForm.method = "POST";
    mapForm.action = "/Application/index.php/ApplicationController/request";   
    var dataArray = {name: "first", lastName: "second"};
    var mapInput = document.createElement("input");
    mapInput.type = "hidden";
    mapInput.name = "data[]";
    mapInput.id = "data[]";
    mapInput.value =dataArray;
    mapForm.appendChild(mapInput);    
    document.body.appendChild(mapForm);
    mapForm.submit();

here is my code to retrieve form data

 if (isset($_POST['data'])) {
 $result_array=$_POST['data'];
 echo 'Data'.$result_array['name'];

but it shows

Severity: Notice

Message: Undefined index: name

how to solve this. Thanks in advance

1 Answer 1

1

try to use

mapInput.name = "name";

instead

mapInput.name = "data[]";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.