@@ -19,7 +19,50 @@ protected function __construct(){
1919 });
2020
2121
22- $ this ->obj ->prototype = \frdl \create ([
22+
23+ $ this ->obj ->prototype = \frdl \create ([
24+ 'getFormFromRequestHelper ' => function (string $ message = '' ,
25+ bool $ autosubmit = true ,
26+ $ delay = 0 ,
27+ \Psr \Http \Message \ServerRequestInterface $ request = null ){
28+ if (null === $ request ){
29+ $ request = (null === $ this ->getContainer (false ) || !$ this ->getContainer (false )->has ('request ' ))
30+ ? null : $ this ->container ->get ('request ' );
31+ }
32+ $ vars = (null ===$ request )
33+ ? $ _POST
34+ : $ request ->getParsedBody ();
35+
36+ $ target = (null ===$ request )
37+ ? $ _SERVER ['REQUEST_URI ' ]
38+ : $ request ->getParsedBody ();
39+
40+ $ method = (null ===$ request )
41+ ? $ _SERVER ['REQUEST_METHOD ' ]
42+ : $ request ->getMethod ();
43+
44+ $ vars = (array )$ vars ;
45+
46+ $ id = 'idr ' .str_pad (time (), 32 , "0 " , \STR_PAD_LEFT ).str_pad (mt_rand (1 ,99999999 ), 8 , "0 " , \STR_PAD_LEFT );
47+
48+ $ html = $ message ;
49+ $ html .='<form id=" ' .$ id .'" action=" ' .$ target .'" method=" ' .$ method .'"> ' ;
50+ foreach ($ vars as $ n => $ v ){
51+ $ html .='<input type="hidden" name=" ' .$ n .'" value=" ' .strip_tags ($ v ).'" /> ' ;
52+ }
53+ $ html .='</form> ' ;
54+
55+ if (true === $ autosubmit ){
56+ $ html .='<script> ' ;
57+ $ html .='(()=>{ ' ;
58+ $ html .='setTimeout(()=>{document.getElementById( \'' .$ id .'\').submit();}, ' .$ delay .') ' ;
59+ $ html .='})(); ' ;
60+ $ html .='</script> ' ;
61+ }
62+
63+ return $ html ;
64+ },
65+
2366 'addContainer ' => function (\Psr \Container \ContainerInterface $ container ) {
2467 return $ this ->getContainer ()->addContainer ($ container );
2568 },
@@ -32,6 +75,9 @@ protected function __construct(){
3275 $ this ->setKernel ( \Webfan \Webfat \App \Kernel::mutex () );
3376 }
3477 return $ this ->kernel ;
78+ },
79+ 'isLocalhost ' => function () :bool {
80+ return $ _SERVER ['REMOTE_ADDR ' ] === '127.0.0.1 ' ;
3581 },
3682 ]);
3783
0 commit comments