helmut2509 Posted January 17, 2017 Share Posted January 17, 2017 Hello, I am just writing a pw app. After successful login the program shall switch to a form with address data, passing an id to the script (which is a pw template). How can I pass the id by POST to the address form? To this purpose I included the following script: <form name="myform" id="myform" method="post" action="../adressdaten"> <input type="hidden" name="adresse_id" id="adresse_id" value="<?php echo $adresse_id; ?>"/> </form> <script type="text/javascript"> document.getElementById('myform').submit(); </script> ..the problem is that that the form is properly displayed, but the id got lost. it is neither in $_POST nor in $input->post->adresse_id. Any idea about how to pass the id? Link to comment Share on other sites More sharing options...
szabesz Posted January 17, 2017 Share Posted January 17, 2017 (edited) Hi, Something like this? More links to solutions: By Soma explained as an admin example:http://soma.urlich.ch/posts/custom-js-in-processwire-admin/ but works on frontend too, as long es we output in the head for dynamic variableshttps://processwire.com/talk/topic/8343-access-page-and-pages-variables-from-inside-a-javascript-file/#entry80823 Edited January 17, 2017 by szabesz more info Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2017 Share Posted January 17, 2017 Your form's action value does not look right: <form name="myform" id="myform" method="post" action="../adressdaten"> What is adressdaten? Link to comment Share on other sites More sharing options...
helmut2509 Posted January 17, 2017 Author Share Posted January 17, 2017 4 minutes ago, szabesz said: Hi, Something like this? you mean to pass the id as url parameter? I want to avoid this, because the user can manipulate the id and might have access to data of other users. Link to comment Share on other sites More sharing options...
helmut2509 Posted January 17, 2017 Author Share Posted January 17, 2017 2 minutes ago, kongondo said: Your form's action value does not look right: <form name="myform" id="myform" method="post" action="../adressdaten"> What is adressdaten? adressdaten is the part of the url which you define when creating the page. But THIS works as the form is properly displayed. Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2017 Share Posted January 17, 2017 (edited) I was not referring to the display since you clearly stated the form displays. The issue is the other side, the server-side. I have never tried it, but I am not sure you can post to a relative URL like that. What is the server response (dev tools) after you post? What happens if you post to the full URL instead? i.e. /something/adressdaten/ Edited January 17, 2017 by kongondo Link to comment Share on other sites More sharing options...
helmut2509 Posted January 17, 2017 Author Share Posted January 17, 2017 9 minutes ago, kongondo said: I was not referring to the display since you clearly stated the form displays. The issue is the other side, the server-side. I have never tried it, but I am not sure you can post to a relative URL like that. What is the server response (dev tools) after you post? What happens if you post to the full URL instead? i.e. /something/adressdaten/ When I use the full URL, it works. Even the adresse_id is being passed but only when it is hardcoded in the above script. When it is inserted with <?php echo $adresse_id; ?> ..it still gets lost :-( Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2017 Share Posted January 17, 2017 Well that's strange. Hard to tell what's happening without seeing the whole context. Just to confirm, when the form is displayed, is the value of $adresse_id correctly output? Link to comment Share on other sites More sharing options...
helmut2509 Posted January 17, 2017 Author Share Posted January 17, 2017 39 minutes ago, kongondo said: Well that's strange. Hard to tell what's happening without seeing the whole context. Just to confirm, when the form is displayed, is the value of $adresse_id correctly output? It is being displayed when it is hardcoded. The above script is included that way: $adresse_id = 123; include('./callAdresse.php'); Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2017 Share Posted January 17, 2017 (edited) So there's your problem then; $adresse_id is not being passed to callAdresse.php, for some reason. I've tested and it works just fine in my case. Edit Not sure where to go from here. Do you have a typo somewhere maybe? Debug errors? Edited January 17, 2017 by kongondo more thoughts Link to comment Share on other sites More sharing options...
helmut2509 Posted January 17, 2017 Author Share Posted January 17, 2017 1 hour ago, kongondo said: So there's your problem then; $adresse_id is not being passed to callAdresse.php, for some reason. I've tested and it works just fine in my case. Edit Not sure where to go from here. Do you have a typo somewhere maybe? Debug errors? 1 hour ago, kongondo said: So there's your problem then; $adresse_id is not being passed to callAdresse.php, for some reason. I've tested and it works just fine in my case. Edit Not sure where to go from here. Do you have a typo somewhere maybe? Debug errors? Now it works. The cause of the error was probably a missing semicolon after the echo command and the incorrect page was cached. Therefore the adresse_id was not displayed even after the patch. Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2017 Share Posted January 17, 2017 I assume then that you did not have a debugger on then? . Would have saved you some headache. Link to comment Share on other sites More sharing options...
helmut2509 Posted January 17, 2017 Author Share Posted January 17, 2017 19 minutes ago, kongondo said: I assume then that you did not have a debugger on then? . Would have saved you some headache. I set $config->debug = true, but the missing semicolon did not cause an error message, though.. Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2017 Share Posted January 17, 2017 Hmm...Tracy would have caught it, I believe . 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now