Solved

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

Posted on 2014-03-04
1
893 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 110

Accepted Solution

by:
Ray Paseur earned 500 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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

737 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