1

I kindly ask for your input in how to send a variable via URL to an other PHP site:

  <form action="deny.php" method="get">
  <div align="left"></div>
  <p><span class="style13" style="height: 23px;">
    <select name="deny" class="style28" style="width: 320px">
      <option value="Select" selected="selected">Select</option>
      <option value="Price">Too expensive</option>
      <option value="Agency">Other Agency</option>
    </select>
    </span></p>
  <p><span class="style13" style="height: 23px;">
  <input type="hidden" name="id" value=<? echo $id; ?> />
  </span> </p>
  <p>
  <? echo '<td><a href="deny.php?submit='.$id.'&deny='.$_GET['deny'].'">Send Feedback</a></td>'; ?>
  </p>
</form>

$id is correct, but $deny is empty

I even tried with $deny (instead of $_GET['deny']) and $_POST[deny] - but $deny is always empty. (can be controlled in the link)

Thanks for your suggestions!

BR,

Stefan

1
  • you can't use a link to submit (without js) the form, change <a> to <input type="submit"..> Commented Dec 19, 2014 at 9:07

6 Answers 6

2

Replace your code with below one:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form action="deny.php" method="get">
  <div align="left"></div>
  <p><span class="style13" style="height: 23px;">
    <select name="deny" class="style28" style="width: 320px">
      <option value="Select" selected="selected">Select</option>
      <option value="Price">Too expensive</option>
      <option value="Agency">Other Agency</option>
    </select>
    </span></p>
  <p><span class="style13" style="height: 23px;">
  <input type="hidden" name="id" value="<?php echo $id; ?>" />
  </span> </p>
  <p>
  <a href="#" id="feedbackLink">Send Feedback</a>
  </p>
</form>
<script type="text/javascript">
    $( document ).ready(function() {
        $('select[name="deny"]').change(function(){
            var link = 'deny.php?submit=<?php echo $id; ?>&deny=';
            $('a#feedbackLink').attr('href', link + $(this).val());
        });
        $('select[name="deny"]').trigger('change');
    });
</script>

You can't use $_GET, $_POST, etc. variables without submitting form.

Hope this will resolved your problem.

Sign up to request clarification or add additional context in comments.

Comments

1

$_GET['deny'] won't be populated until you submit the form to the current script.

Don't try to use PHP to construct the URL. Let the browser do it. Just put a submit button in the form and have appropriate inputs and action. That's what forms are for.

Comments

1
<form action="deny.php" method="get">
  <div align="left"></div>
  <p><span class="style13" style="height: 23px;">
    <select name="deny" class="style28" style="width: 320px">
      <option value="Select" selected="selected">Select</option>
      <option value="Price">Too expensive</option>
      <option value="Agency">Other Agency</option>
    </select>
    </span></p>
  <p><span class="style13" style="height: 23px;">

  </span> </p>
  <p>
  <input type="submit" value="submit">
  </p>
</form>

2 Comments

Thank you for your comments and suggestions. I tried it with this echo "<input type='submit' name='submit' value='" . $id . "'>"; now everything will be passed, but the button name is the value of the id instead of the name "send feedback"... :-)
which text you want to display on button?
0
<form action="deny.php" method="get">
    <div align="left"></div>
    <p>
        <span class="style13" style="height: 23px;">

            <select name="deny" class="style28" style="width: 320px">
                <option value="Select" selected="selected">Select</option>
                <option value="Price">Too expensive</option>
                <option value="Agency">Other Agency</option>
            </select>
        </span>
    </p>
    <p>
         <span class="style13" style="height: 23px;">
              <input type="hidden" name="id" value="<?php echo $id; ?>" /> 
         </span>
    </p>
    <p>
         <input type="submit" value="Send Feedback" value="submit" />
    </p>
</form>

 <?php
      if (isset($_GET)) {
          var_dump($_GET);
      }
 ?>

Comments

0
<form action="/deny.php?id=<? $id ?>" method="get">

<input name="submit" type="submit" value="Feedback" />

Did the trick :-)

Thanks,

Stefan

Comments

0

Try this one,it has been tested.

<form action="your_page.php" method="GET"> <!--you may use POST for security as well -->
      <select name="deny">
        <option value="">Select Option</option>
        <option value="Price">Too expensive</option>
        <option value="Agency">Other Agency</option>
      </select>
      <!-- you msut have $id = something -->
      <input type="hidden" name="id" value="<?php echo $id; ?>" /> 
      <input type="submit" value="Send Feedback" value="submit" />
  </form>

 <?php
      echo "<pre>";print_r(($_GET));
 ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.