And the following code on page2, which is clearly incomplete:
<?php
$name = $_GET[‘name’];
$product = $_GET[‘product’];
?>
A stupid question, but what else must I add to the PHP code? When I click the link, nothing happens. “foo” does not get added to the “name” input. When I use my original JavaScript code I’m referencing both an Id and a value:
document.getElementById(‘name’).value=location.search.split(‘&’)[1];"
Could someone please help?
Thank you
Regards,
Dazed and .
PS: I could stick with my JavaScript code but I’m not sure if this method is secure or not?
I wouldn’t say that doing it this way is necessarily any more secure than with JS, as I could still change the value your JS receives by altering the query string.
thanks for your help - excuse the late reply. I’ve been trying out the code you provided but it isn’t passing any of the variables
What if I leave out the document.getElement stuff and attach the <?php $_GET [‘$name’] ?> directly to the form input? For example, name=“<?php $_GET [‘$name’] ?>”?
I’m not sure if I should append the the php code to name or value. I also don’t know if I should do $name = $_GET[‘name’] or just $_GET[‘name’]. Either way, nothing has worked so far. As I said, I’m just starting to learn php!
I also need to load a specific item on page2, replacing id_item=6 in the following code, with id_item=4 in the query string. I haven’t added the php code to the iframe code because I wouldn’t know where to begin.
it’s working perfectly now! :tup: Thank you. You’ve been a big help.
One last question, though… Where would I put the htmlspecialchars code in order to “sanitize” the php. That was one of the main reasons why I wanted to use php instead of JavaScript.
I like using the [fphp]filter_input[/fphp] function as it saves you an extra step of checking if the variables are set. If they’re not, it’ll just return null rather than throwing an error.