Jump to content

[SOLVED] problem with form posting


adam291086

Recommended Posts

My form variables are not being posted and i can't work out why.

 

Here is the form

 

<?php
$ImageDirectory = "../upload/pictures/thumbnail";
echo '<form action="delete.php" method="post">';
$BigImage = "../upload/pictures/picture";
foreach (glob("$ImageDirectory/{*.gif,*.jpg,*.png,*.GIF,*.JPG,*.PNG}", GLOB_BRACE) as $image)
{
//remove .. for url
$dir = str_replace("..", "", "$BigImage");

//get name for url
$name = str_replace("$ImageDirectory", "", "$image");

//get name on it's own
$fullname = str_replace("/", "", $name);


echo '<br />';
echo $fullname;
echo '<br />';
echo '<img src="'.$image.'">';
echo '<br />';
echo "www.adamplowman.co.uk".$dir.$name;
echo '<br />';
echo "<a href=\"http://www.adamplowman.co.uk\cycling\admin".$dir.$name."\">View full Image</a>";
echo '<br />';
echo '<input type="radio" name="delete[".$image."]" value="Delete" />Delete';
echo '<br />';
echo '<br />';
echo '<input type="submit" value="Delete Selected">';
echo '<br />';
echo '<br />';

}


?>

 

 

and this is the delete script. The variable adam is no where to be seen

 

<?php
$adam = $_POST['delete'];

foreach($adam as $key => $value){
if($value == "1"){
unlink($key);
}
}
echo $adam;
?>

Link to comment
Share on other sites

on the following html form notice the input of type hidden.  You can have multiple hidden fields on a form.  These arent visible to the user but are passed along with all the other visible elements such as the textboxes etc.

 

<form action="process.php" method="post" name="myform" id="myform">
  <p>Name 
    <input type="text" name="textfield">
  </p>
  <p> 
    <input type="submit" name="Submit" value="Submit">
    <input name="somevalue" type="hidden" id="somevalue" value="<?PHP echo $somevalue; ?>">
  </p>
</form>
[code]

When the form is posted, your script at the other end can simply use $_post[somevalue] to read the values from the names of all the hidden fields.

Let me know if this helps.

Steve

[/code]

Link to comment
Share on other sites

this wont work because it is the value property you need to be posting, not the name.  Otherwise when you are trying to read in the post at the other end, how do you know what the field is going to be called?

 

  echo '<input type="radio" name="delete[".$image."]" value="1" />Delete';
[code]

really should be written like this:

[code]
  echo '<input type="radio" name="deleteimage" value="<?PHP $imageid ?>" />Delete';
[code]

This way you always know that the name of the value is deleteimage but the value can be whatever it chooses.

[/code][/code][/code]

Link to comment
Share on other sites

yep

 

here is the code

 

<?php
$ImageDirectory = "../upload/pictures/thumbnail";
echo '<html>';
echo '<body>';
echo '<form action="delete.php" method="post">';
$BigImage = "../upload/pictures/picture";

foreach (glob("$ImageDirectory/{*.gif,*.jpg,*.png,*.GIF,*.JPG,*.PNG}", GLOB_BRACE) as $image)
{
//remove .. for url
$dir = str_replace("..", "", "$BigImage");

//get name for url
$name = str_replace("$ImageDirectory", "", "$image");

//get name on it's own
$fullname = str_replace("/", "", $name);


echo '<br />';
echo $fullname;
echo '<br />';
echo '<img src="'.$image.'">';
echo '<br />';
echo "www.adamplowman.co.uk".$dir.$name;
echo '<br />';
echo "<a href=\"http://www.adamplowman.co.uk\cycling\admin".$dir.$name."\">View full Image</a>";
echo '<br />';
echo '<input type="radio" name="delete[]" value="'.$image.'" />Delete '.$image;
echo '<br />';
echo '<br />';
echo '<input type="submit" value="Delete Selected">';
echo '<br />';
echo '<br />';

}
echo '</from>';
echo '</html>';
echo '</body>';


?>

Link to comment
Share on other sites

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.