1. Create table [SQL Command]:
CREATE TABLE `mytable` (
`id` int(10) unsigned NOT NULL auto_increment,
`fullname` varchar(255) NOT NULL,
`phone1` varchar(255) NOT NULL,
`phone2` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
2. Create 2 chunks:
Name:
myform
<p class="error">[+validationmessage+]</p>
<form method="post" action="[~[*id*]~]" id="dbForm" name="dbForm">
<fieldset class="form3">
<label for="Name">Full_Name:
<p><input name="fullname" id="name" class="form" type="text" eform="Full Name::1:Expected at least two words:#REGEX /^\w+\s\w+/i" /></p></label>
<label for="phone1">Phone #1:
<p><input name="phone1" id="phone1" class="form" type="text" /></p> </label>
<label for="phone2">Phone #2:
<p><input name="phone2" id="phone2" class="form" type="text" /></p> </label>
<label> </label><p><input type="submit" name="submit" id="submit" value="Submit" /></p>
</fieldset>
</form>
Name:
thankyou
<h1>thank you!</h1>
Click <a href="[~[*id*]~]">HERE</a> to see it worked.
3. Create DataGrid TV:
Variable Name: dataGrid
Caption: [*dataGrid*]
Input Type: Text
Default Value: @SELECT fullname, phone1, phone2 FROM mytable
Widget: Data Grid
only changed/added this:
Column Names: Full Name, Phone 1, Phone 2
Field Names: fullname, phone1, phone2
Column Types: Text
4. Create a snippet:
Name:
PhoneList
<?php
function PhoneList( &$fields )
{
global $modx;
// Init our array
$dbTable = array();
$dbTable[fullname] = $modx->db->escape($fields[fullname]);
$dbTable[phone1] = $modx->db->escape($fields[phone1]);
$dbTable[phone2] = $modx->db->escape($fields[phone2]);
// Run the db insert query
$dbQuery = $modx->db->insert($dbTable, 'mytable' );
return true;
}
return $html;
?>
5. Call it all:
<div style="background:#fff;">[*dataGrid*]</div>
[!PhoneList!]
[!eForm? &noemail=`true` &formid=`dbForm` &eFormOnBeforeMailSent=`PhoneList` &tpl=`myform` &thankyou=`thankyou`!]
That should be it!
//EDIT: fixed wrong "DataGrid" to
dataGrid + ... return $html; ...
phone1 instead of phone.