?
Solved

best way to dynamically create jquery validation for a form created dynamically in php

Posted on 2014-03-04
1
Medium Priority
?
903 Views
Last Modified: 2014-03-07
Hello

I am writing an ajax website with forms created dynamically in php and the validation done dynamically in jquery from the php.

This can be quote tedious with a lot of concatentation and potential for errors. I was wondering if you experienced web developers had a good way of making your jquery validation dynamically.

I saw an idea on this post
http://stackoverflow.com/questions/21439639/building-dynamic-rules-for-jquery-validate-from-php-array

where the jquery is created in javascript from json but to be honest I would rather create it on the server as i dont know php/query/json very well as it is. What i'm doing isnt my usual job.

But given as this must be a common task I am assuming there is a framework/approach for doing this.

I did look at formbuilders and they dont seem too popular

Thanks
0
Comment
Question by:andieje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39903355
Unless you choose a framework, there is no magic bullet; you just have to do the work.  And if you choose a framework, then you have to learn the framework in addition to learning PHP and jQuery, so that is probably a longer path than doing it by hand.

Make a Google search for the exact phrase "jquery validation example" to find examples.  Although it does no client-side validation, this article shows the basics of jQuery and AJAX.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

You may want to learn about PHP HEREDOC syntax.  I find it very easy and powerful for making templates and HTML fragments.  An example is in the code snippet.  You can think of HEREDOC as notation that is like a double-quoted string.  It has variable substitution and if you use it with object-oriented notation, you don't have to escape the quote marks, so it reduces syntax issues and parse errors.

<?php // html5_template.php
error_reporting(E_ALL);

// CREATE VARIABLES FOR OUR HTML
$dat = date('r');
$xyz = "Hello World.  It is $dat";

// CREATE OUR WEB PAGE IN HTML5 FORMAT
$htm = <<<HTML5
<!DOCTYPE html>
<html dir="ltr" lang="en-US">

<head>

<meta charset="utf-8" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

<title>HTML5 Page in UTF-8 Encoding</title>

</head>

<body>

<p>$xyz</p>

</body>

</html>
HTML5;

// RENDER THE WEB PAGE
echo $htm;

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question