1

perhaps a simple question but I cant find an explanation: I have a php gallery application to make. One of the functions of the gallery is to show the miniatures of all uploaded photos. Every photo has to have a checkbox near it and there has to be a button that leads to a php script which does something like: show only checked photos in a new tab.

My problem is that the submit button doesn't work and I dont know what's the problem

EDIT: ok some more info what doesnt work: the buttons and the gallery show up, it's just the button doesnt run the script session.php when clicked. Here is the code:

echo '<form name ="gallery" method="post" action="session.php" enctype="multipart/form-data">';
for ($i=0; $i<count($files); $i++) {

    echo ($i+1).'. <img src="'.$files[$i].'" />  '; 
    echo '<input type="checkbox" name="gallery" value="'.($i+1).'">';
    echo "<br/>";

}
echo '<input type="submit" form = "gallery" name = "showchecked" value="button1" >';
echo '</form>';
9
  • 1
    You have invalid HTML, that might be the cause of your problem. And nctype="multipart/form-data" seems unnecessary since you don't have any file inputs. Also, you have a closing a tag but no opening one. Commented Jan 2, 2014 at 11:03
  • "Does not work" is not a very insightful description. Commented Jan 2, 2014 at 11:03
  • Try to add opening <a> tag. I have modified it in answer Commented Jan 2, 2014 at 11:07
  • check your error logs.. and remove if there are any redirects in session.php so you can see the errors.. Commented Jan 2, 2014 at 11:13
  • 1
    How do you know that session.php is not running when the form is submitted? Commented Jan 2, 2014 at 11:14

2 Answers 2

3

Try echo '<input type="submit" name="showchecked" value="button1" >'; (without the form = "gallery" bit).

If I am correct you should only use form="yourform" when an input field / button is outside the actual form and this is only supported in HTML5. See http://dev.w3.org/html5/markup/input.submit.html (Thanks Gerald)

And as Gerald mentioned in a comment, your checkboxes all have the same name, you should either give them all a different name or do name="gallery[]".

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

1 Comment

I'd count w3.org as a "decent source": dev.w3.org/html5/markup/input.submit.html
0

You are missing starting <a> tag here.

echo ($i+1).'. <img src="'.$files[$i].'" /></a>

Right form will be

for ($i=0; $i<count($files); $i++) {

echo "<a>"; // add this
echo ($i+1).'. <img src="'.$files[$i].'" /></a>  ';

2 Comments

those are just typos from simplifying the code for stackoverflow, sorry, gonna edit those ones out
You should provide your code without typos. Otherwise you are getting wrong answers!

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.