473,811 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP Form Validation + JavaScript + gettext

hgeithus
20 New Member
Hi. I'm doing a form at my website, and I found this document which is very interesting: Javascript form validation - doing it right .

I have a little question though. All the documents within my page has the *.php extention since I'm using PHP the most. I'm also using gettext to translate strings to other languages. If I want to translate the string "hello", I would write it like this in my *.php document:

Expand|Select|Wrap|Line Numbers
  1. <?php echo _("hello");?>
In my navigation bar, I have links to different languages. Pressing one of these links sets a global variable that gettext uses to identify what language that's active and then translates all the strings which are marked in same way as the code above..

I encounter a problem when mixing this JavaScript code with my PHP code. Because I want the output messages from the validation to be translated as well. For instance if a field is left blank the JavaScript outputs the message: "Required field cannot be left blank". I want this message to be translated as well.

So what is the best strategy here? Should I do it all in PHP? Does anyone have experience with this kind of setup? Thanks in advance.

Regards
Dec 1 '08 #1
9 2766
Markus
6,050 Recognized Expert Expert
hgeithus, please do not hi-jack another person's thread. This is against the forum rules. If you have a question, start your own thread.

Moderator.
Dec 1 '08 #2
hgeithus
20 New Member
I wanted to ask a question, therefore I started this thread. What seems to be the problem?
Dec 1 '08 #3
Markus
6,050 Recognized Expert Expert
@hgeithus
You didn't 'start this thread', you hi-jacked someone else's thread. That is the problem.

Moderator.
Dec 1 '08 #4
hgeithus
20 New Member
Ah, Sorry about that :S I didn't realise I posted inside another thread :S

Hmm...

Can you please delete this thread? It looks silly now with this discussion.
Dec 2 '08 #5
Markus
6,050 Recognized Expert Expert
@hgeithus
It happens.

@hgeithus
Negative. Then you might not receive an answer. I'll have a look at your question now.
Dec 2 '08 #6
Markus
6,050 Recognized Expert Expert
I can't, at the moment, think of an efficient way to do this. I could only suggest you make an ajax call to a page with the error that your javascript validation threw and the language you want it changing to. Then have the php page return the errors counterpart in whatever language you specify.

Quite an ugly way of doing it.. but, hey.
Dec 2 '08 #7
Atli
5,058 Recognized Expert Expert
Could you not simply set the message your JavaScript is supposed to use via PHP when the page is loaded?

Something like:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <title><?php echo _("Page title"); ?></title>
  4.     <script type="text/javascript">
  5.     var fieldRequiredMsg = '<?php echo _("Fill out the fields! NOW!"); ?>';
  6.     </script>
  7. </head>
  8. <body>
  9.     <button onclick="alert(fieldRequiredMsg);">Click me</button>
  10. </body>
  11. </html>
  12.  
Dec 3 '08 #8
Markus
6,050 Recognized Expert Expert
@Atli
Doh! I'm an idiot..
Dec 3 '08 #9
hgeithus
20 New Member
That was kinda sweet :D
Thank you :)
Dec 22 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
4264
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the second form when it is called. Both forms are .htm files that call themselves when the submit button is press via the following command in each form: <form method="post" action="<?php $server?>">
6
507
by: Darren | last post by:
I have a form that has 10 fields on it. I have made all of them "Required". I also am using vb if statements to decide whether or not each field should be on the page. I am using the vb to compare values in my database and if a certain field equals something then the field is shown on the form. When the form is displayed in the browser, it could any increment of the 10 fields on it. My problem is that unless all fields are being shown...
2
2013
by: iam247 | last post by:
Hi I have an ASP form which only includes an option list. The list is dynamically created but includes a default value, which is an instruction "Select a group". The code is shown at bottom. I want to ensure the user does not submit the form with the default value selected.
16
2257
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate individual fields, such as an "Email Validation Script" or a "Phone Validation Script". Is it ok to put all these scripts on page as they are or should they be joined in some way together to be one script? I'm a total JavaScript newbie and am completely...
9
4184
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
27
4767
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
11
3004
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
0
2242
by: Richie01 | last post by:
Ok, here i have the code for the form...but whenever i click update, delete or search all it does is close the form and nothing is done to the database. Could someone be kind enough to help me out here... import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; import java.net.*; import java.util.*; public class EmpForm extends JFrame
3
3302
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using it's mail () function to send the mail. However, as I got more into that topic I realized that one should be really concerned about the validation part to prevent spam abuse. There are shiploads of 'mail scripts' available with each of them has...
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.