1

My image upload form on my profile edit page isn't working. The two forms must be separate as they work independently. The image upload script uploads the image before the profile edit form is submitted.

I tested the image upload on a separate page where it was the only thing on the page and it worked. So I am assuming it is the other form that is messing it up. The two forms are acting on different scripts and both methods are posts.

Here is the jscript

<script type="text/javascript" src="imageupload/scripts/jquery.min.js"></script>
<script type="text/javascript" src="imageupload/scripts/jquery.form.js"></script>
<script type="text/javascript" >
  $(document).ready(function() { 
    $('#photoimg').live('change', function() { 
        $("#preview").html('');
        $("#preview").html('<img src="imageupload/loader.gif" alt="Uploading...."//>');
        $("#cropimage").ajaxForm({ target: '#preview' }).submit();
    });
  }); 
</script>

Here's the form;

<form id="cropimage" method="post" enctype="multipart/form-data" action="../imageupload/ajaximage.php">
  <input type="file" name="photoimg" id="photoimg" class="filebutton"/><br>
</form>

Here is the other form. Its a long one;

    echo '<form action="phpscripts/artistupdate.php" method="post" id="profileedit"><input type="text" name="artistname" value="'. $row['artistname'].'" class="name"     maxlength="80"><span id="editlink"><t1>Your profile link will be: <br><a     href="http://newbornsounds.co.uk/artists/artist.php?artist='.$row['artistname'].'">    <b>http://newbornsounds.co.uk/artists/artist.php?artist=<FONT style="BACKGROUND-COLOR: yellow">'.$row['artistname'].'</font></b></a></span><br><div id="urlwarn"><t1>Please note that if you change your url all the links you have placed outside of NBS will be affected.</t1></div>';
  }
}
?>
<hr>
<?php 
  $username = $_SESSION['username'];
  $pass = $_SESSION['password']; 
  include ("../database.php");
  $result = mysql_query("SELECT * FROM members WHERE username='$username' AND     password='$pass' AND artist='Y'");

  while($row = mysql_fetch_array($result)){
    echo '<div id="artistsbio"><textarea name="bio" rows="10" cols="80" name="bio" value="'.     $row['bio']. '" class="bio">'. $row['bio']. '</textarea><br><div id="probwarn"><t1>Everything is still in the beta stage so there are bound to be a few problems. If you spot one please <a     href="mailto:artists@newbornsounds.co.uk"><b>tell us about it.</b></a></t1></div>';
  }
?>
<br><br>
<input type="submit" name="submit" value="Done" class="button"></form>
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
Jacob Windsor
  • 6,750
  • 6
  • 33
  • 49
  • 1
    What does the complete html of the forms look like? You cannot nest forms. – jeroen Jun 07 '12 at 16:57
  • where is the other form? – Kasia Gogolek Jun 07 '12 at 16:58
  • make sure you have two submit buttons for each of your form – COLD TOLD Jun 07 '12 at 17:01
  • Do you expect both forms to execute at once or only the one the user indicates? – Nathaniel Ford Jun 07 '12 at 17:03
  • Only the forms the user submits should be submitted. The are independent from eachother. And the upload image form submits with javascript when a file is selected – Jacob Windsor Jun 07 '12 at 17:10
  • I have added the code for the other form. I know this code is a bit strange but its the only way i could get that one to work. – Jacob Windsor Jun 07 '12 at 17:13
  • New development. It works when a submit button is added to the image form. This probably means that its something to do with the javascript – Jacob Windsor Jun 07 '12 at 17:27
  • 2
    Just as an aside, you can definitely write cleaner code, and it will make your life much easier. You don't need to be echoing html wholesale: just close your php and write it, so it's readable to you, and then open the php tag again to complete the code section. – Nathaniel Ford Jun 07 '12 at 17:31
  • Yeah i know I can. Its force of habit really. I only started learning php about a week ago and only found out you could do that really recently. I have started to change my ways – Jacob Windsor Jun 07 '12 at 17:36
  • It seems to me that the javascript isnt calling the php file when another form is on the page. I know nothing about javascript so any advice? – Jacob Windsor Jun 07 '12 at 17:48

1 Answers1

0

There is no submit button in your cropimage form, which might be the pb. If I understand well, you want it to be submitted when there is a change in the photoimg field, without submit button.

Try Submitting a form by pressing enter without a submit button (displaying a submit button outside the screen if you don't want to display it).

BTW, jquery live is deprecated. http://api.jquery.com/live/

Community
  • 1
  • 1
Pixou
  • 1,719
  • 13
  • 23
  • Thanks for the answer. I have figured it out now. Turns out the javascript in my memberstoolbar was messing around with the javascript line that was submitting the form. But thanks for saying the .live function is deprecated. Didn't realise – Jacob Windsor Jun 11 '12 at 13:00
  • Strange, i switched the live to on but it no longer works with on. Whats happening? – Jacob Windsor Jun 11 '12 at 13:04