Hello OG,
thanks for the example. I followed the tutorial Bob wrote and all the files have been created, the database tables are in place. I wrote a basic form that is ready to send to the database. Looking at your code I don’t see how it knows to INSERT nor which table it’s to be sent to.
Sorry, still trying to get my head round how this works!
I have a component in the core/components/contactGeneral/
The schema.xml file looks like this.
<?xml version="1.0" encoding="UTF-8"?>
<model package="contactGeneral" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
<object class="General" table="general" extends="xPDOSimpleObject">
<field key="title" dbtype="varchar" precision="200" phptype="string" null="false" default="" />
<field key="firstName" dbtype="varchar" precision="200" phptype="string" null="false" default="" />
<field key="SecondName" dbtype="varchar" precision="200" phptype="string" null="false" default="" />
<field key="email" dbtype="varchar" precision="200" phptype="string" null="false" default="" />
<field key="telephone" dbtype="varchar" precision="200" phptype="string" null="false" default="" />
<field key="enquiry" dbtype="mediumtext" phptype="string" null="false" />
</object>
</model>
The general.map.inc looks like this
<?php
$xpdo_meta_map['General']= array (
'package' => 'contactGeneral',
'version' => '1.1',
'table' => 'general',
'fields' =>
array (
'title' => '',
'firstName' => '',
'SecondName' => '',
'email' => '',
'telephone' => '',
'enquiry' => NULL,
),
'fieldMeta' =>
array (
'title' =>
array (
'dbtype' => 'varchar',
'precision' => '200',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'firstName' =>
array (
'dbtype' => 'varchar',
'precision' => '200',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'secondName' =>
array (
'dbtype' => 'varchar',
'precision' => '200',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'email' =>
array (
'dbtype' => 'varchar',
'precision' => '200',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'telephone' =>
array (
'dbtype' => 'varchar',
'precision' => '200',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'enquiry' =>
array (
'dbtype' => 'mediumtext',
'phptype' => 'string',
'null' => false,
),
),
);
My form is very basic.
<form action="[[~10~]]" method="post" id="sendContact">
<input type="text" name="obj_firstName" />
<input type="text" name="obj_secondName" />
<input type="text" name="obj_email" />
<input type="text" name="obj_telephone" />
<textarea name="obj_enquiry"></textarea>
<input type="submit" value="send" />
</form>
I just don’t know what code should be in the snippet on Document 10 where the form takes you to, to then send that data to the Database.
Does your code tie in with the object that I created?
$object = null;
if (!empty($_POST) && isset($_POST['submitMyForm'])) {
if (isset($_POST['obj_id')) $object = $modx->getObject('MyObject', $_POST['obj_id']);
if (empty($object)) {
$object = $modx->newObject('MyObject');
}
$object->fromArray($_POST, 'obj_');
$object->save();
}
A little lost unfortunately but learning.