473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

PHP Form Validation + JavaScript + gettext

hgeithus
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 2703
Markus
6,050 Expert 4TB
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
I wanted to ask a question, therefore I started this thread. What seems to be the problem?
Dec 1 '08 #3
Markus
6,050 Expert 4TB
@hgeithus
You didn't 'start this thread', you hi-jacked someone else's thread. That is the problem.

Moderator.
Dec 1 '08 #4
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 Expert 4TB
@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 Expert 4TB
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 Expert 4TB
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 Expert 4TB
@Atli
Doh! I'm an idiot..
Dec 3 '08 #9
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
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...
6
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...
2
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....
16
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...
9
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...
27
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...
11
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...
0
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...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.