Hi there,
I have an issue (one of many) i don't seem to be able to grasp how to use page controllers properly as i'm sure this current issue relates to this. I have a simply one field form that checks an external api and returns an xml list dependant on the MessageID sent in the form this is then styled by using an associated XSL file.
This works, if i hard code the MessageID in and obviously don't use the form, i get a nice styled response. when i add the form in it still works but it opens a new blank page with the data but the end of the URL is the form name. I'm trying to render the response of the form query within the same page or at the very least a page that looks like it's in the site.
Below is my current base code and as i said i'm sure the issue lays with my lack of knowledge with page controllers.
Any help please.
Mick
class SMSResponsePage_Controller extends Page_Controller {
function msgCheck() {
$fields = new FieldList(
TextField::create("msgID","Msg ID")
);
$actions = new FieldList(
new FormAction('domsgcheck', 'Get message')
);
$validator = new RequiredFields('msgID');
$form = new Form($this, 'msgCheck', $fields, $actions, $validator);
return $form;
}
function domsgcheck($data, $form){
$theID = $_POST["msgID"];
$data = http_build_query(array(
'orgcode' => 'XXXX',
'apipin' => 'XXXX',
'msgid' => $theID,
'checkmode' => 'TESTXML'
));
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $data
)
));
$xmlresponse = file_get_contents('http://XXXXXXXXXXXXXXXXXX.asp', false, $context);
$xml = new DOMDocument();
$xml->loadXML(trim($xmlresponse));
$xsl = new DOMDocument;
$xsl->load('../Search/css/sms.xsl');
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
$response = $proc->transformToXML($xml);
return $response;
}