tags:

views:

85

answers:

3

Lately I've been using client-side jQuery scripts to fill in forms when users edit records in a custom CMS I've built. Server side script is PHP.

How to do it isn't my issue. My question to you is opinion seeking. My clients have to have javascript turned on to use my CMS which so far hasn't been a problem as most users don't take issue or just don't know how to turn it off. Using server side script like PHP takes much more code to fill things like , radio and checkbox elements. Using jQuery makes it a breeze by having my php fill an object and passing out values to the various form elements.

Thoughts on this are welcome. Thanks for reading.

Edit: seengee is right - there's not enough information above. I'm pulling an entry from a database and populating the form so the user can make changes to existing information. The javascript is far less cumbersome programming wise. I feel like I already know the safe answer to this. I'm just looking for your thoughts. Sorry if there's no definitive answer here—I thought it might be a fun discussion.

+2  A: 

If it's not necessary, and won't make much of a difference (most users won't experience a difference), then don't do it. If, on the other hand, you plan on expanding your client-base in the future, and expect more people to be using this application, I would go ahead and provide it if it's a necessary feature to your application.

When it comes to hours, money, and requirements, you ought to ask yourself if it's necessary. If it is necessary, what priority should be attributed to it. It seems from what I've read that this isn't immediately necessary, but could be in the future. As a result, I would probably start to brainstorm about how to do this efficiently - maybe begin to lookup some form-handling classes, or begin designing your own.

Jonathan Sampson
Thanks for actually providing a little insight Jonathan :)
jeerose
+1  A: 

It seems like a rather roundabout approach to write PHP to create variables for javascript to update form elements after the page is loaded. I do it in PHP. It's not that hard:

<?php if($var) echo 'checked="checked"' ?>

And you don't have the page load and then change when the javascript runs.

-- Edit: I'm assuming that you're talking about filling in forms BEFORE the user does anything. If you're talking about AFTER/AS the user does stuff, the javascript is very appropriate.

Scott Saunders
You're right in assuming before - my question didn't provide enough information. The javascript is used in this case to populate a form from an entry in the database. Your PHP is definitely easy enough for a checkbox. What about a select element with 50 options in it? Thanks for your thoughts.
jeerose
For a select, loop through the options and add <?php if($var == $value) echo 'selected="selected"' ?>Or you copy and paste a lot :) Better to loop if you can get your values in an array, which is also handy for validating acceptable input.
Scott Saunders
A: 

I'm going to assume a user clicks an 'adit' button or something to edit the page before the page is sent with jQuery.

Why not use PHP sessions? When a user clicks the edit button, load the entire article (or whatever) into the session and then have it echo'd at the editing page. That'd avoid the problem of users not having javascript enabled.

klpmsdgv