Hexana
Hexana

Reputation: 1135

PHP Redirect to Anchor Link on Another Page When Passing Radio Button Value

I am attempting to pass a form value to a textbox on another page with php. Specifically, I want to link to the textbox on the other page when the form button on page1 is submitted.

Page1:

 echo '<td><input type="radio" name="myId" value= " ' . $myId . ' "></td>';

 echo '<input name="mybutton" type="submit" value="Submit">';

Page2

if (isset($_POST['myId'])) {   
header('Location: http://localhost/dirc/mypage.php#link');
$id = trim($_POST['myId']); 
}//if no id passed
else {
$id = "";
}

Then on Page2 where the anchor is:

//if button clicked on Page1, redirect to here on Page2 and display the value in the textbox:

<a name="link">
<input type="textbox" value="<?php echo $myId;?>">

Give the above, if I click mybutton, the redirect to the anchor on the other page works, however the value of the radio button does not get passed! If I comment out....

//header('Location: http://localhost/dirc/mypage.php#link');

The myId gets passed but the redirect to the anchor doesn't work.

On Page1 I have also tried checking if mybutton and myId isset:

if (isset($_POST['myId']) && ($_POST['mybutton')) 

But this doesn't make any difference.

There is nothing wrong with myId getting passed to Page2 but the minute I add the header location redirect, this stops the data getting passed?

Any help appreciated.

Upvotes: 0

Views: 763

Answers (1)

Happy Coding
Happy Coding

Reputation: 2525

Change to :

header('Location: http://localhost/dirc/mypage.php?myId='.$_POST['myId']);

If you want to access it use

<input type="textbox" value="<?php echo $_GET['myId'];?>">

---Edited---

 header('Location: http://localhost/dirc/mypage.php?myId='.$_POST['myId'].'#'.$_POST['myId']);

Upvotes: 2

Related Questions