lundi 16 décembre 2019

How to pass multiple checkbox values to php

Currently i have a HTML form that collects some metadata about some files, and each user as to fill some fields. I want to register some keywords about the data. I could ask them to write the keywords by hand on a normal text box, but i would prefer to have a list of checkboxes of about 10/15 values.

Then i need to pass only the checked values to a PHP file, using $_POST. My problem is that i assign a variable to those values, and then i call that variable in a DOM event. I´m generating a XML file, and currently i have the HTML ready to register these keywords in text input. I understand how to create the checkboxes, and pass them as an array to PHP., by reading other questions here. But i can´t understand how to pass this array to a $dom->createElement situation, and preferably separated by commas.

PHP

//Pull data from HTML form
$keywordsString = $_POST['keywords'];

// Creates xml document
$dom = new DOMDocument();
    $dom->encoding = 'utf-8';
    $dom->xmlVersion = '1.0';
    $dom->formatOutput = true;

$xmlFileName = 'example_example.xml';

// Adds metadata to xml
$metadata = $dom->createElement('MD_Metadata');

    $idInfo = $dom->createElement('identificationInfo');
        $descriptiveKeywords = $dom->createElement('descriptiveKeywords');
                $CharacterString = $dom->createElement('CharacterString', $keywordsString);
                $descriptiveKeywords->appendChild($CharacterString);
            $idInfo->appendChild($descriptiveKeywords);
    $metadata->appendChild($idInfo);

$dom->appendChild($metadata);

$dom->save($xmlFileName);

I can´t figure out how to pass checkbox values to that $keywordsString , but separated by commas. The rest i can understand and write, using the other questions about this kind of issue.

Thanks in advance for all help provided.




Aucun commentaire:

Enregistrer un commentaire