Simon
Simon

Reputation: 2733

html and php input type submit doesn't work

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>';

Upvotes: 1

Views: 1011

Answers (2)

putvande
putvande

Reputation: 15213

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[]".

Upvotes: 3

chanchal118
chanchal118

Reputation: 3647

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>  ';

Upvotes: 0

Related Questions