$path = MODX_CORE_PATH . 'components/dataease/';
// get POST variable this is captured
$accNo = $_POST['accNo'];
$output = '';
// Check if form has been submitted and that the accNo exists in the db
if (isset($_POST['submit']) && $_POST['accNo'] == 'accNumber') {
// Get info from the database
$query = $modx->newQuery('accno');
$query->select($xpdo->getSelectColumns('Dataease','Dataease','',array('*')));
$query->where(array('accNumber:LIKE' => '$accNo'));
// Place it into a variable for output
$dataease = $modx->getCollection('Dataease',$query);
// Count the returned rows, should only ever be 1
$output .= '<p>Total: '. count($dataease) . '</p>';
// Show the found data
foreach($dataease as $sql) {
$fields = $sql->toArray();
$output .= $modx->getChunk('showData', $fields);
}
return $output;
} else {
// Get the form chunk
$form = $modx->getChunk('dataEntryForm');
return $form;
}
<h2>Enter Account Number:</h2>
<form method="POST" action="">
<input name="accNo" type="text" value="" />
<input name="submit" type="submit" value="submit" />
</form>
This question has been answered by opengeek. See the first response.
&& $_POST['accNo'] == 'accNumber'
The if statement will only be true if you enter "accNumber" in your form field.
Just removeand it should work.&& $_POST['accNo'] == 'accNumber'
$path = MODX_CORE_PATH . 'components/dataease/';
var_dump($_POST['submit']);
var_dump($_POST['accNo']);
// get POST variable this is captured
$accNo = $_POST['accNo'];
$output = '';
// Check if form has been submitted
if (isset($_POST['submit'])) {
// Get info from the database
$query = $modx->newQuery('accno');
$query->select($modx->getSelectColumns('Dataease','Dataease','',array('*')));
$query->where(array('accNumber:LIKE' => '$accNo'));
var_dump($query);
// Place it into a variable for output
if (!$query) {
return "Query failed";
} else {
$dataease = $modx->getCollection('Dataease',$query);
// Count the returned rows, should only ever be 1
$output .= '<p>Total: '. count($dataease) . '</p>';
// Show the found data
foreach($dataease as $sql) {
$fields = $sql->toArray();
$output .= $modx->getChunk('showData', $fields);
}
}
return $output;
} else {
// Get the form chunk
$form = $modx->getChunk('dataEntryForm');
return $form;
}
I was kicking myself after I dropped the exclamation mark in and everything started working as intended. Ah well, happy days in the end.