I’m just curious if there’s any special code I need to use, or if it would just look like this;
action="[[phpSnippet]]"
or if I just need to upload the php to a folder and link it like normal.
Not quite.
You need to either:
1) Put the snippet on a separate page and make the action a link to that page action=[~##~]" (where ## is the id of the page with the snippet).
2) Put the snippet on the same page and have the form post to itself action="[~[*id*]~]". In that case the snippet needs to make sure it’s a repost before acting.
1. I’m guessing the page it’s posted on needs to have a completely blank template applied to it.
2. What do you mean by "making it a repost"? I didn’t see any option for it in the snippets options.
Sorry if I’m bugging you. I got a user page-creation form working using a form outside of the CMS(by editing the database), but now I need to test my user session recognition feature while logged into the CMS.
Here is a simple example of posting a form back to the same page:
<?php
/* Example login form
* form posts back to the same page
usage: uncached [!ThisSnippetName!]
*/
$output ='';
// get the current document id to use in the action of the form
$this_docid = $modx->documentIdentifier;
// if the form has been posted
if(isset($_POST['submit']) && isset($_POST['password'])){
// do whatever actions here if the form has been posted
$output .='<div align="center">Welcome '.$_POST["webusername"].', you are logged in...</div>';
}else{
// otherwise show the form
$output .='<form id="loginForm" name="loginForm" method="post" action="[~'.$this_docid.'~]">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="112"><b>Login</b></td>
<td width="188"><input name="webusername" type="text" class="textfield" id="webusername" /></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input name="password" type="password" class="textfield" id="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Login" /></td>
</tr>
</table>
</form>';
}
return $output;
?>