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

  • Home
  • SEARCH
  • 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 6655135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:28:42+00:00 2026-05-26T01:28:42+00:00

I have a form on my site that runs some basic JS validation when

  • 0

I have a form on my site that runs some basic JS validation when the user clicks submit, before the form is submitted, but I am getting an error ‘unterminated string literal’ when checking some of the fields.

I understand what this error is (users adding line breaks in a textarea in this case) but I cannot think of a way of avoiding/fixing it.

Here is how I declare the form –

<form id="<?php echo $form_name; ?>" 
      name="<?php echo $form_name; ?>" 
      class="standard-form" 
      method="POST" action="" 
      onsubmit="return validate_form('<?php echo $form_name; ?>')">

And here is how I am checking the field that is causing me trouble –

var your_query = document.forms['enquiry']['your_query'].value
if(your_query === ''){
    result = false;
}

Any help here would be appriciated.

Thanks.

  • 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-26T01:28:43+00:00Added an answer on May 26, 2026 at 1:28 am

    My guess is $form_name contains a single quote character: '

    First, you should really escape that output with htmlentities and json_encode:

    <form id="<?php echo htmlentities($form_name); ?>"
          name="<?php echo htmlentities($form_name); ?>"
          class="standard-form"
          method="POST"
          action=""
          onsubmit="return validate_form(<?php echo htmlentities(json_encode($form_name)); ?>)">
    

    See also Pass a PHP string to a Javascript variable (including escaping newlines)

    Next, don’t use that onsubmit intrinsic event attribute and don’t pass the form name to it; use proper DOM scripting (or jQuery) and event handling in your JavaScript file:

    (function() {
        var form = document.getElementById("<?php echo json_encode($form_name); ?>");
        form.addEventListener('submit', onSubmit, false);
    
        function onSubmit() {
            // manipulate variable `form` as necessary
            // without having to pass around a `form_name`
        }
    }());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site that uses a GET form to allow a user to
Basically I have a form that goes full screen automatically. But while Inet runs,
I have a site that has a simple HTML button in a form. All
I have a form that submits a search for blogs on my site via
On my site, I have a form that users fill out to become a
I have a win form that creates a site in IIS7. One function needs
I have a form on my site that lets users direct a message at
I have a simple form on an ASP.NET MVC site that I'm building. This
I have a form on my site. The user enters their e-mail and selects
Quick question, looking for some recommendations. I have a site that will be requesting

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.