Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1044175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:47:06+00:00 2026-05-16T15:47:06+00:00

I am using jQuery Form Plugin http://jquery.malsup.com/form/ to submit my form. Here is the

  • 0

I am using jQuery Form Plugin http://jquery.malsup.com/form/ to submit my form.

Here is the code that is used to submit the form.

var options = { 
    beforeSubmit:  showRequest,  // pre-submit callback 
    success:       showResponse,  // post-submit callback 
    url:           'recaptcha.php',  // override for form's 'action' attribute 
    type:          'POST'
}; 
$('#myform').submit(function() { 
    $(this).ajaxSubmit(options); 
    return false; 
});

This is the form I am using for testing.

<form action="" method="post" style="margin:10px 0;" id="myform">
<div id="recaptcha_image"></div>
<input type="text" name="recaptcha_response_field" id="recaptcha_response_field" size="30"  />
<input type='file' name='filename' size='10' />
First name: <input type="text" id="fname" name="fname" />
<input type="submit" value="Submit" id="submit_button" /> 
</form>

Here is the code snippet in recaptcha.php

$results['success'] = true;
$results['msg'] = 'Security code is valid!';
$results['is_fname_empty'] = empty($fname);
$results['is_fname_isset'] = isset($fname);
echo json_encode( $results );
return; 

Here is the problem I found with jQuery Form Plugin.

Case I> If I submit the form without entering anything for #fname, the returned result is as follows:

"is_fname_empty":true,"is_fname_isset":false

Case II> If I submit the form with entering 0 for #fname, the returned result is as follows:

"is_fname_empty":true,"is_fname_isset":false

As you can see, it seems that there is no way that I can differentiate what the user enters.
I really need to know whether the user DOES NOT enter anything or the user enters 0.

Anyone can help?

Thank you

// Update based on comments from dconde //

Hello all,

I set up a working script so that I can explain my problem easily.

<html> // testAjaxForm.php
<head> 
    <script type="text/javascript" src="js/jquery/jquery-1.4.2.js"></script> 
    <script type="text/javascript" src="js/jquery/jquery.form.js"></script> 
    <script type="text/javascript"> 
        $(document).ready(function() { 
            $('#myForm').submit(function() { 
                $(this).ajaxSubmit(); // called first
                return false; 
            });        
        }); 
    </script> 
</head> 

<body>
  <form id="myForm" action="verify.php" method="post"> 
      Name: <input type="text" name="fname" /> 
      <input type="submit" value="Submit Comment" /> 
  </form>
</body>
</html>

<?php // verify.php
require_once('./FirePHPCore/FirePHP.class.php');
require_once('./FirePHPCore/fb.php');
FB::setEnabled(true);
ob_start(); // avoid 'headers already sent error'

FB::log($_POST,      '$_POST');
FB::log(strlen($_POST['fname']), 'strlen(name)');
FB::log(empty($_POST['fname']), 'empty(fname)');
FB::log(isset($_POST['fname']), 'isset(fname)');
$is_fname_empty = empty($_POST['fname']) && $_POST['fname'] != 0 && $_POST['fname'] != '0';
FB::log($is_fname_empty, '$is_fname_empty');

?>

Here is the printed information from FirePHP.

1> I submit the form without entering any information.

$_POST: array('fname'=>'')
strlen(name): 0
empty(fname): TRUE
isset(fname): TRUE
$is_fname_empty: FALSE

2> I submit the form with 0.

$_POST: array('fname'=>'0')
strlen(name): 1
empty(fname): TRUE
isset(fname): TRUE
$is_fname_empty: FALSE

As you can see, there is NO difference between two submission if we only consider the empty, isset, and the method provided by dconde. However, on thing that is different from my last experiments is that the string length can help me make difference. I don’t know why it doesn’t work for me last time.

Thank you all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:47:07+00:00Added an answer on May 16, 2026 at 3:47 pm

    The best way to test for this kind of emptiness in PHP is via string length, ie.

    isset($_POST['fname']) && (strlen($_POST['fname']) !== 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the JQuery plugin AjaxForm (http://jquery.malsup.com/form/) to submit the contents of a form
I am using this plugin: http://malsup.com/jquery/form/#getting-started I am having issues, getting it to submit
I'm using the jquery form plugin ( http://malsup.com/jquery/form/ ) to upload a file via
I'm using the JQuery Form Plugin ( http://jquery.malsup.com/form/ ) to create an Ajax Form.
I'm creating a form using Django, JQuery and JQuery Form plugin (http://jquery.malsup.com/form/) and I
I have a form which is built dynamically using this jQuery plugin http://code.google.com/p/jquery-dynamic-form/ When
I am using this jQuery plugin: http://api.jquery.com/slideToggle/ I have this code: <div id=panel><form action=postit.php
I'm using the jquery form plugin (http://jquery.malsup.com/form/) to show the results of a submitted
I'm using the jQuery validation plugin found here: http://plugins.jquery.com/project/validate In my form I have
I using jquery form plugin from malsup http://jquery.malsup.com/form/ In the http://jquery.malsup.com/form/#getting-started example, how do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.