Solved

ajax form error

Posted on 2010-08-14
6
468 Views
Last Modified: 2012-06-27
hi
i am trying to use jquery form. however, what is happening instead of the success appearing in the div it is appearing in the php page that the form is passing too. i have attached the code and would be grateful if someone could tell me what is wrong? many thanks
this call the form from onpress

<script type="text/javascript">
function fileadd(){ 

          jQuery.facybox({ div: '#addform' });
}

form script
----------------------------------------------------------

<script type="text/javascript">

// prepare the form when the DOM is ready 
 
    // bind form using ajaxForm 
    $('#addform').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#htmlExampleTarget', 
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            $('#htmlExampleTarget').fadeIn('slow'); 
        } 
		
    }); 


</script>

form
------------------------------------------------------

<div id="addform" style="display:none;">
  <form action="filesadd.php" method="post" class="webform">
    <fieldset>
    <legend><span>Enter a File</span></legend>
    <label for="box">Select a Box</label>
    <select name="box">
      <option SELECTED VALUE="">Select a Box</option>
      <?php
do {  
?>
      <option value="<?php echo $row_Recordset1['boxref']?>"><?php echo $row_Recordset1['boxref']?></option>
      <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
      
    </select>
    <label for="fileno">File Number:</label>
    <input id="fileno" name="fileno" class="text" type="text" />
	<div id="htmlExampleTarget"></div>
    <label for="authorised">Authorised By:</label>
    <input name="authorised" type="text" class="text" id="authorised" value="<?php echo $_SESSION['kt_name_usr']; ?>" />
    </fieldset>
    <input class="submit" type="submit"  name="submit" value="Add File" />
  </form>
</div>

fileadd.php
-------------------------------------------------------

$sql = "SELECT custref FROM files WHERE custref = '$fileno' ";
$result = runSQL($sql) or die(mysql_error());
if (mysql_num_rows($result)>0){
   echo '<div style="background-color:#ffa; padding:20px">' . $fileno . 'Is already in the database' . '</div>';

}else{
   //insert into db;
   echo '<div style="background-color:#ffa; padding:20px">' . $fileno . "Box: " . $box . $authorised . 'Successfull' . '</div>';
   $sql = "INSERT INTO `files` (customer, authorisation, boxstatus, boxref, custref, filestatus) VALUES ('$customer', '$authorised', '$boxstatus', '$box', '$fileno', $filestatus)";
   $result = runSQL($sql) or die(mysql_error());
   //echo 'This record is valid';
   //header("Location: http://localhost/sample/admin/files/index.php");
		//exit();
}

Open in new window

0
Comment
Question by:peter_coop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 33437459
I'm hardly an expert on this, just getting AJAX (without JQuery) to work last month.  But I did get it to work.

What I'd try is making the distance between <div> and </div> much smaller.  I had some trouble (like what you describe) when I used a large division.  When I get it small, very small, I have much more luck.
0
 

Author Comment

by:peter_coop
ID: 33437513
hi. sorry i'm not sure i'm following you. how can i make this smaller?

<div id="htmlExampleTarget"></div> do you mean the id?
 thanks
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 33437901
I was looking at the other div.  That was a mistake on my part.  

I looked at your code some more but I don't know enough about JQuery.  Sorry.
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

Accepted Solution

by:
peter_coop earned 0 total points
ID: 33438189
thanks. i have narrowed it down to the facybox plugin. if i open the form in facybox then the form plugin does not work  does anyone know if facybox strips tags from form or html? thanks
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 33438247
Since you solved this yourself and I'm the only person who has responded, I suggest you try the following (with the caveat that I've never tried this myself).

1. Accept your solution  (I don't know if you can just do that but I won't object and nobody else is likely to get the close notice other than moderators).  

I *think* that will give you a refund.  (You could ask in the moderator section).

2. Post a new question.
0
 

Author Comment

by:peter_coop
ID: 33440262
thanks. have closed the thread.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Anyone familiar with PhotoSwipe? 3 39
JSON/JQuery/AJAX Error Identification 2 70
Why does my submit button remain disabled 3 31
Add Promise to Existing Code 6 24
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question