Solved

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

Posted on 2014-03-04
1
876 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
1 Comment
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now