Jump to content

Add another upload box button acting as "submit" button


Mr.Canuck

Recommended Posts

If you look at this form: kmkwebdevelopment.com/formtest/upload.php you will see that when you click on the "add another upload box" button, instead of it adding another upload box, it is submitting the form for some reason. Can anyone see where the error lies?

Relevant snippet of code below:

<?php //deafult number of upload boxes
$upload_quant = 4;
//if the user increased the number of boxes
if(isset($_POST['increase_upload']))
{
//increasing the number of upload boxes
$upload_quant = $_POST['previous_upload'] + 1;
}
$upload_quantity = $_POST['previous_upload'];
//getting all the names into an array
$uplaoded_array = array();
for($i=0;$i<$upload_quantity;++$i)
{
$ii = $i+1;
$upload_name = 'upload'.$ii;
$get_upload_name = $_POST['$upload_name'];
array_push($uplaoded_array,$get_upload_name);
} ?>

<form class="uploadform" action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post" enctype="multipart/form-data" onSubmit="return CheckForm(this);">
<?php IsThereErrors("0", $_iserrors); ?>
<input type="hidden" name="_referer" value="<?php echo $_referer ?>">
<input type="hidden" name="_next_page" value="1">
<p class="form_expert_style"><input name="URL" type="text" value=""/></p>

<table>
<tr>





<td>First Name *</td>





<td><input type='text' size='30' name='firstname' onBlur="FieldBlur(this.name+'_tooltip')" <?php mark_if_error("firstname", "") ?> value="<?php echo isset($_values["firstname"]) ? htmlspecialchars($_values["firstname"]) : "" ?>"></td>
</tr>
<tr>





<td>Last Name *</td>





<td><input type='text' size='30' name='lastname' onBlur="FieldBlur(this.name+'_tooltip')" <?php mark_if_error("lastname", "") ?> value="<?php echo isset($_values["lastname"]) ? htmlspecialchars($_values["lastname"]) : "" ?>"></td>
</tr>
<tr>





<td>E-mail *</td>





<td><input type='text' size='30' name='email'  onblur="FieldBlur(this.name+'_tooltip')" <?php mark_if_error("email", "") ?> value="<?php echo isset($_values["email"]) ? htmlspecialchars($_values["email"]) : "" ?>"></td>
</tr>
<tr>





<td>Company Number *</td>





<td><input type='text' size='30' name='companynumber' onBlur="FieldBlur(this.name+'_tooltip')" <?php mark_if_error("companynumber", "") ?> value="<?php echo isset($_values["companynumber"]) ? htmlspecialchars($_values["companynumber"]) : "" ?>"></td>
</tr> 

<?php for($i=0;$i<$upload_quant;++$i)
{
$ii = $i+1;
$upload_name = 'upload'.$ii;
echo <<<_END
<tr>
<td>Upload $ii</td>
<td><input class="image" type='file' size='30' name='$upload_name'></td>
</tr>
_END;
}
echo <<<_END
<tr>
<td>
<input type="hidden" value="$upload_quant" name = "previous_upload"/>
<input type="submit" name="increase_upload" value="Add another upload box" />
</td>
<tr>

<td><input type="submit" name="SubmitBtn" onClick="CheckForm1();" value="SUBMIT" /></td>
</tr>
</table>
</form>
_END;
}
?>





</html>

<?php 

 

Thanks

The input type of your Add Another Box is set to 'submit'. This calls the method submit() of your form.

 

You should switch this type='submit' to type='button', and include an onclick='addBox()' attribute. Where addBox() attribute is you would probably wanna call your javascript function that adds extra elements.

 

<input type="button" name="increase_upload" value="Add another upload box"  onclick='addBox()' />

 

You could use attribute onclick='return false; addBox()' on an input type=submit. The return false; bit would cancel the form from being submitted.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.