|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon May 25, 2020 3:26 pm Post subject: |
|
|
edidur wrote: |
calling action:
Code: |
<form action="https://www.edidur.com/api.php?call=writingstats&user_id={$user->_data['user_id']}&word_count=1111&writing_date={$smarty.now|date_format:"%Y-%m-%d"}" method="post" _self> |
with an api return of:
Code: | {"id":"7470","user_id":"2","word_count":"1111","writing_date":"2020-05-23","created":"2020-05-23 18:54:10","updated":"2020-05-23 18:59:50"} |
So the fundamental issue seems to be, why is the HTML Form element of wcount not being assigned into the api calling url? (Why isn't the submitted number being stuffed into the url, like the user_is and writing_date is?) |
Whatever you put in action= is a GET parameters, no matter what kind of request you use.
If you want to create a form with POST method, which would be accessible via POST parameters, use proper HTML fields.
F.e.
Code: | <form action="https://www.edidur.com/api.php" method="post">
<input type="hidden" name="call" value="writingstats"/>
<input type="hidden" name="user_id" value="{$user->_data['user_id']|escape}"/>
<input type="hidden" name="word_count" value="1111"/>
<input type="hidden" name="writing_date" value="{$smarty.now|date_format:"%Y-%m-%d"|escape}"/>
…
|
|
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon May 25, 2020 3:51 pm Post subject: |
|
|
You said:
"Definitely worth a shot, I will check out the $_POST value before hand."
A suggested test is to code a statement in the PHP script that will print out the contents of $_POST immediately before the Smarty command to display the template.
Code: | if(isset($_POST)) print_r($_POST); |
What is the result of that test? |
|
Back to top |
|
edidur Smarty Rookie
Joined: 21 May 2020 Posts: 12
|
Posted: Tue May 26, 2020 1:37 am Post subject: |
|
|
So word_count=$_COOKIE['wordcount'] won't be translated then in the TPL?
Wow, this not having any php to work with is a real PITA.
What do you think about moving the entire html form to a plugin, would that work?
(And thanks for all of the help you have given me bsmither, it is nice to know I am not alone in this. ) |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Tue May 26, 2020 2:46 am Post subject: |
|
|
Based on what you have said and have not said, I will conclude you do not have access to the PHP code.
Thus, working with that conclusion, you have no means of determining whether or not PHP has actually received the POST payload from the web server. And, you have no means of determining whether or not there is any PHP code that is changing the contents of the $_POST array before Smarty sees it.
All you see is the API output with no means to make any fixes necessary to get what you need.
However, the question is then asked, "Would moving the entire html form to a plugin work?" If, still working on the conclusion that you do not have access to the PHP code, installing a Smarty plugin would not be possible.
So, finally, if the API has no code to process the form elements from a POST payload, and is possibly actively doing something to discard anything that does arrive in a POST payload, then your goal has become very difficult if not impossible. |
|
Back to top |
|
edidur Smarty Rookie
Joined: 21 May 2020 Posts: 12
|
Posted: Tue May 26, 2020 8:23 pm Post subject: |
|
|
Request URL: Code: | https://www.edidur.com/api.php?call=writingstats&user_id=2&word_count=$_POST[%27wordcount%27]&writing_date=2020-05-26 |
Note that it is escaping the wordcount $_POST variable with %27.
After learning the development tools (thanks for pointing them out bsmither!) I am seeing the $_POST['wordcount'] is being properly set (Development tools, network Form Data: Returning proper number)
So it looks like the only thing that is holding me up is that the apostrophe is not being escaped properly. Is this something that could be in my .htaccess file?
Or, conversely, is there a way to escape out the apostrophe properly in smarty? |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Tue May 26, 2020 11:16 pm Post subject: |
|
|
Please contact the author/publisher of the API. That person may be able to support your requirements. |
|
Back to top |
|
edidur Smarty Rookie
Joined: 21 May 2020 Posts: 12
|
Posted: Wed May 27, 2020 12:29 am Post subject: |
|
|
Well, I appreciate you sticking with me this far bsmither.
I'll wander on I guess. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|