ModX Evolution: pass variable from url to form text field on page load
I need to pass string from url:
..开发者_StackOverflow社区/page.html?code=123456
to a form (eform snippet in modx) just once is page loaded (link with url and parameter) Thanks for answer...
My solution:
1. create a new snippet called GetCode
<?php
if( !function_exists('eformGetCode') ) {
function eformGetCode(&$fields,&$templates){
global $modx;
$code = strip_tags($_GET['codeID']);
$templates['tpl']=str_replace('[+display_code+]',$code,$templates['tpl']);
return true; } }
return '';
?>
2. Add eform call (and snippet) on webpage:
[!GetCode!]
[!eForm? ... ... &eFormOnBeforeFormParse=`eformGetCode` !]
3. In eform chunk with form code add line:
<input name="code" id="code" value="[+display_code+]" eform="::1:" type="text"/>
5. Now when you put parametr in url like:
..../page.html?code=123456
this should appear in form.
you would do this exactly like you would in php..
$myVar = $_GET['code'];
If you are having issues, take a peek in the modx error logs...
-sean
Solution by KudyKam is better than official solution in MODX docs, in which they use a database. http://wiki.modxcms.com/index.php/Populate_eform_with_dynamic_data
精彩评论