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 9223895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:11:02+00:00 2026-06-18T04:11:02+00:00

I have a simple HTML file with a form. <form action=register.php method=get id=submitform> First

  • 0

I have a simple HTML file with a form.

<form action="register.php" method="get" id="submitform">
    First Name:
            <input type="text" class="fb-input" name="fname" id="firstname" />
            <br>
    <div class="fb-error">
    </div>

    <input type="button" name="signupBtn" id ="sub" value="Sign upw">

</form>

When I press the submit button, this will be checked at the jquery if the field is empty.

$(document).ready(function(){
    $("#sub").click(function(){
       register();
    });
});

function register(){
    var firstname=$("#firstname").val();

    if(firstname==""){
        $(".fb-error").show().html("You must fill the fields.");

    }else{
        $(".fb-error").hide();
        $("#submitform").submit();
    }
}

Then after being checked, it will be submitted to the php file to further check the characters inputted in the form, then will it will echo if an invalid character was found.

What I want is, the checking that i am doing after page submission in the php file will be transferred inside the jquery. Example:

function register(){
    var firstname=$("#firstname").val();

    if(...){
         <?php
            if(preg_match(....)){....}
         ?>
    }else{
        .....
    }
}

I tried this and it didn’t work. I guess i cant put php inside the jquery. The reason i want to put the php inside the jquery is for me to be able to show an error message in the div part of the HTML because once I submit the page, It goes to another blank page where the error message of the php shows up.

What im doing is like the regisration of facebook that once you submit it and you input wrong characters, an error message will show up at the bottom. We are required to use php, jquery is just optional.

Could anyone help me with this? Or could suggest a better way to do this?


Updated:

Html code:

<html>
<head>
<title>Facebook Registration</title>
</head>
<body>
<form action="register.php" method="get" id="submitform">
    First Name:

    <?php $fname = isset($_POST['fname']) ? $_POST['fname'] : ''; ?>

    <input type="text" class="fb-input" name="fname" value="<?php echo $fname;     ?>">
        <br>

    <div class="fb-error">
    </div>

    <input type="submit" name="signupBtn" id ="sub" value="Sign upw">

</form>

Php file:

<?php
$fname=$_GET['fname'];

if((preg_match("/^[a-zA-z]{1,}$/",$fname))){
    echo "registered";
}
else{
    var_dump($_POST);
    echo "<form id='retForm' method='post' action='index.php'>";
    echo "<input type='hidden' name='fname' value='$_POST[fname]'>";
    echo "<script>$(document).ready(function() { $('#retForm').submit() });</script>";
}

?>
  • 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-06-18T04:11:04+00:00Added an answer on June 18, 2026 at 4:11 am

    What you can do in PHP, is simple. You can validate the form on the PHP script on the other page, and if you find any errors, you can redirect the form back with the $_POST variable.

    Something like this on your form

    <?php $fname = isset($_GET['fname']) ? $_GET['fname'] : ''; ?>
    <input type="text" class="fb-input" name="fname" value="<?php echo $fname; ?>">
    

    Now, in your register.php, you can write this snippet

    <?php
        if(isset($_GET['signupBtn'])) {
            //do validation on $_GET['fname']
            //if the validation fails, send it back to the form with the value like this
            echo "<form id='retForm' method='GET' action='originalForm.php'>";
            echo "<input type='hidden' name='fname' value='$_GET[fname]'>";
            echo "<script>$(document).ready(function() { $('#retForm').submit() });</script>";
        }
        else {
            //proceed with registration
        }
    ?>
    

    This will send the fname back as part of the $_GET variable and will be displayed in the form input. You can use AJAX calls to validate as well, but since you wanted to minimize the jQuery code, this would be one of the few ways you can achieve it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple html form that looks like the following <form action=search.php method=get>
I have this simple piece of HTML code: <div> <input type=file name=english-file /> </div>
I have a simple form like this one: <form ENCTYPE=multipart/form-data action=upload.php method=POST> <p>UPLOAD FILE:
I have a simple HTML Form <form id=uploadForm method=post action=/cgi-bin/test.cgi enctype=multipart/form-data> <input type=submit name=add_something
I have a simple HTML form containing a file input. When the form is
I have three simple html or php file that I'm going to create. What
I am trying to create simple user registration form. I have an index.html file
I want to have a simple HTML file act as a bootstrap for a
can anyone help? I have a simple html file which i am filling via
I have a simple html form. This form has a specific width and margin

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.