Jump to content

Pass parameter to script


helmut2509
 Share

Recommended Posts

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

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 variables
https://processwire.com/talk/topic/8343-access-page-and-pages-variables-from-inside-a-javascript-file/#entry80823

 

Edited by szabesz
more info
Link to comment
Share on other sites

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

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 by kongondo
Link to comment
Share on other sites

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

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

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 by kongondo
more thoughts
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...