-
- 24,544 Posts
Remember that the snippet will run once when the page is first loaded and the $_POST array is empty. Then it will run again when the form is submitted. This code would capture both events:
<?php
if( isset($_Post['Submit'] )) {
$_SESSION['userLogon'] = $_POST['user'];
$modx->log(modX::LOG_LEVEL_ERROR, 'Submit is set ' . print_r($_POST, true));
} else{
$modx->log(modX::LOG_LEVEL_ERROR, 'Submit is not set ' . print_r($_POST, true));
}
-
- 24,544 Posts
That doesn't mean the code isn't running. It just means that 'Submit' is not an element in the $_POST array. The code *isn't* running, however, because your form's action is another page. The user is forwarded to that other page so the snippet never runs a second time.
-
- 24,544 Posts
The 'action' defaults to posting to (and reloading) the current page.
If you post to another page, the code of your snippet will never run.
One solution is to post to the current page, let your snippet run, then use cURL at the end of your snippet to post to the other page.
http://stackoverflow.com/questions/1217824/post-to-another-page-within-a-php-script. I think you could then use $modx->sendRedirect() to go to the other page, but I'm not sure.
-
- 178 Posts
Thanks again Bob. I had a look at the curl option but it brings in the form from the other site. I am beginning to think that it just isn't possible in the short term and that I will have to put up with two login processes for now and perhaps spending the time finding a solution later.
Thanks for your help
-
- 24,544 Posts
It is possible with cURL to fill in the form fields on the other site and submit without the user seeing anything, though I've never done it.