Browse Source

formdata class

master
Odilitime 4 years ago
parent
commit
8812e2a53e
2 changed files with 90 additions and 0 deletions
  1. 62
    0
      src/FormData.cpp
  2. 28
    0
      src/FormData.h

+ 62
- 0
src/FormData.cpp View File

@@ -0,0 +1,62 @@
#include "FormData.h"

// how do we match up nodes to components to extract the current values out of the components?
// well we link input components back to node (and/or nodes back to components)
// or we create a form UI component
std::unique_ptr<std::map<std::string, std::string>> buildFormData(std::shared_ptr<Node> formNode, std::unique_ptr<std::map<std::string, std::string>> result) {
if (!result) {
result = std::make_unique<std::map<std::string, std::string>>();
}
// check this node
TagNode *tagNode = dynamic_cast<TagNode*>(formNode.get());
if (tagNode) {
auto typePropIter = tagNode->properties.find("type");
bool skip = false;
std::cout << "formData.buildFormData - tagNode element " << tagNode->tag << std::endl;
if (typePropIter != tagNode->properties.end()) {
if (typePropIter->second == "submit") {
skip = true;
}
if (typePropIter->second == "checkbox") {
// FIXME: see if it's checked or not
skip = true;
}
if (typePropIter->second == "radio") {
// FIXME: see if it's checked or not
skip = true;
}
}
auto namePropIter = tagNode->properties.find("name");
if (!skip && namePropIter != tagNode->properties.end()) {
auto valuePropIter = tagNode->properties.find("value");
if (valuePropIter != tagNode->properties.end()) {
auto it = result->find(namePropIter->second);
if (it == result->end()) {
std::cout << "INPUTElement.buildFormData - setting " << namePropIter->second << " to [" << valuePropIter->second << "]" << std::endl;
result->insert(std::pair<std::string, std::string>(namePropIter->second, valuePropIter->second));
} else {
(*result)[namePropIter->second] = valuePropIter->second;
}
}
}
}
// check children noedes
for (auto &child : formNode->children) {
//std::shared_ptr<TagNode> tagNode = std::dynamic_pointer_cast<TagNode>(child);
//if (tagNode) {
result = buildFormData(child, std::move(result));
//}
}
return result;
}

std::unique_ptr<std::vector<Node>> searchNodeTree(const std::shared_ptr<Node> &node, std::unique_ptr<std::vector<Node>> ret) {
return ret;
}

FormData::FormData(std::shared_ptr<TagNode> start) {
// recurse down find all interesting tags
std::unique_ptr<std::vector<Node>> formNodes = std::make_unique<std::vector<Node>>();
searchNodeTree(start, std::move(formNodes));
}

+ 28
- 0
src/FormData.h View File

@@ -0,0 +1,28 @@
#ifndef FORMDATA_H
#define FORMDATA_H

#include <string>
#include <map>
#include "html/TagNode.h"

std::unique_ptr<std::map<std::string, std::string>> buildFormData(std::shared_ptr<Node> formNode, std::unique_ptr<std::map<std::string, std::string>> result);

class FormData {
public:
FormData();
FormData(std::shared_ptr<TagNode>);
// creates arrays out of values
//void append(std::string name, std::string value);
//void append(std::string name, std::string value, str::string filename);
// overwrites value
//void set(std::string name, std::string value);
//void set(std::string name, std::string value, str::string filename);
// gets value (list if array)
//void getAll(std::string name);
std::map<std::string, std::string>::iterator entries();
//std::map<std::string, std::string>::iterator keys();
//std::map<std::string, std::string>::iterator values();
std::map<std::string, std::string> data;
};

#endif

Loading…
Cancel
Save