Jump to content

Variable sent in form


Go to solution Solved by Barand,

Recommended Posts

I am trying to send a php variable called $angle to another script called penalty.php along with an already establish variable called $goaly1 in a URL send method but can't get it going.

 

I have the $goaly1 variable working on its own and I've added in the $angle form so it's probably that bit of the script that doesn't gel.

 

Do I need the penalty.php instruction twice for example?

 

Any suggestions would be appreciated.

 

 

<html>

<body>

<form method="post" action="penalty.php">

<input type="checkbox" name="angle" value="1">Angle?</input>

<?php

$angle = $_POST['angle'];

?>

 

<a href='penalty.php?

angle=<?php echo $angle ?>&

goaly1=<?php echo $goaly1 ?>

'>

draw it</a>

</html>

Edited by muppet77
Link to comment
https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/
Share on other sites

Making the href span multiple lines like that is not a good idea. Could cause problems.

 

Where is $angle supposed to be coming from? Either it's set in this script, or if it comes from POST data then your script doesn't do anything and just keeps that form (and penalty.php gets the value from $_POST).

  • Solution

Use a hidden field in the form for the goalie value

 

 form.php

<?php
    $goalie = 'someCalculatedValue';          // calculate the goalie value
?>

<html>
<body>
    <form method="post" action="penalty.php">
        
    <input type="hidden" name="goalie1" value="<?=$goalie?>">  <!-- store the goalie value in a hidden field -->
    
    <input type="checkbox" name="angle" value="1">
    <input type="submit" name="btnSubmit" value="Submit">
    </form>

</body>
</html>

penalty.php

<?php
$goalie = $_POST['goalie'];
$angle = $_POST['angle']

...

?>
Edited by Barand

Thanks Barand.

 

Had a quick go but couldn't get it going.

 

Should there be some php in there?

 

Eg rather than your

 

<input type="hidden" name="goalie1" value="<?=$goalie?>"> <!-- store the goalie value in a hidden field -->

 

Should it be

 

<input type="hidden" name="goalie1" value="<?php echo $goalie ?>"> <!-- store the goalie value in a hidden field -->

Edited by muppet77
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.