jquery check what changed in a form [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to check if any data in a form has been changed by a user, either removed, added or modified in any way and send the data to PHP so that I only have to execute specific update commands instead of updating everything. What's the best way of doing this?

First decide do you need to check updated data in client side or server side.
If you check updated data in client side, you will prevent submit unwanted data and submit will be quick.
To achieve this, when you submitting form before submit, in following js method check which data has changed. First in document ready function, create hidden variables or global js variables and assign initial values of form. Then in following method check current form values with those variables values. Then you can identified which data has been changed. Then from form remove existing values.( You may be need to aware of mandatory fields when remove data).
$("#myform").submit(function(){
// Put code here.
});
If you are planning to check data in server side, you can place logic in server side and prevent be messing client side code and store heavy data. To achieve this you have to do extra database call. After get data from form, in server side do extra db call which use to initially load data to form and check what are the changed data and then save only updated data.

Related

PHP - how to generate a URL on save like JSFiddle does? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to recreate something you might know from imgur or jsfiddle - you just type something or upload images, then you click "save" or "upload" and then you get a original link in form of imgur.com/smth or jsfiddle.net/smth. How is this done? I've created simple website where I can write notes and save them and it works perfectly well for myself, but I wanted to share it with some of my friends and I have absolutely no idea how can the "save" button attach their changes to new URL every time they press it? I know this is pretty basic but I couldn't find anything on the matter online and I really have no idea how to handle this issue, excepting I'll be writing their changes to different SQL rows.
Thanks for any clues :)
If you're trying to create something and let people edit it and keep the same link you could do it with PHP and mySQL.
I think the easiest way would be to have one page to create the initial note and one to update/view it. Once you create it the save button would add it to a database with a unique id of some kind like an auto increment number. To send the page you would use a link like www.somepage.com/info.php?id=1. The "id=1" part would be the unique id within the database. In info.php, you would need to use $get_["id"] and set that to equal the database id row and load the info from there. Then you could allow edits to that row from that page. You would have to set the save button to update the row.
To get something like somepage.com/smith, if you're on a linux server, you would use htaccess and mod_rewrite.
This is a really down and dirty gist of how you could do this, but it should send you in the right direction.

Dynamically Generating Web Page with new URL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there any way to generate webpages dynamically.for example I have a website called abc.com in which I have included a form with many fields.
When a user submit this form,I want a new webpage abc.com/xyz to be created.Wondering if this is possible.
Of course it's possible. Anything is possible in programming/development.
See the following PHP manual for a good tutorial: http://www.php.net/manual/en/domdocument.savehtmlfile.php
This is possible in variety of ways.
You can pass GET variables in URL (example.com/page?var1=1&var2=2) and use this variables to generate unique page by predefined template.
If you don't want to use variables in URL, you can POST them to page via form request or ajax call.
Alternatively you can use .htaccess configuration files to rewrite your URL and use url segments as variables (example.com/var1/var2), this is common approach in MVC systems, where first/second variables are class/method names.
So here's an example:
You have a page.php where form resides.
User fills a form and submits it.
Form goes trough AJAX call, submitting it to request.php page
request.php parses it and stores it in DB, generating unique id
AJAX event recieves from request.php a unique id and redirects user to review.php
with url (example.com/review/uniqueID) or (example.com/review.php?uniqueID)
review.php recieves uniqueId, get's info from DB by it and displays requested info

Best way to simple frontend that stores data [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a simple page that shows 4 different divs, all with a <h1> title (or other tag that shows text) and a form (with 1 input text) and a submit button... so far so good.
My answer is simple: I am looking for a way that:
when the user inserts a text and submit the form, the <h1> title shows the text that the user wrote
the form disappear (or takes style display:none)
this will take effect even if I refresh the page or view page in a different computer (probably need to save the data in a DB)
restart this process from the beginning (even if I need to code again).
This is for a mini game to provide to users 4 different choices and, if the user A select option 1, the <h1> will show text something like "User A was the first to choose this option. Please select a blank option" and, after the 1st raw over (point 4 described above), restart all forms.
NOTE: I am not asking in the way to "please do the code for me". I also searching for a way to store data in <php ?> - finding redbeanphp project.
I am also a newbie in SQL (just started to study SQLi last month to android development). My question is ONLY to looking for the best way to do this and what I need.
This would be the workflow:
When you click a button to submit the form JavaScript will send the form data to the server as an AJAX request and wait for a response from the server.
The PHP code on the server will read the data from the AJAX request and save it in a database and echo a success response along with the text to display.
Your JavaScript will receive this success message and hide form from the DOM and display the text in the header.
If you want the data to persist on the page on reload then you can save a flag in PHP session. Sessions persist in until you close browser window.
4.1 Use another AJAX call remove the flag from the session and reload the content.
So, if you are good with HTML and CSS you need:
JavaScript, AJAX, a JavaScript library to make things easier such as JQuery.
A server side language such as PHP.
A database to persist data. There are many choices. I am going to recommend MySQL just because there so many tutorials for it out there.

Save client-side changes to server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a very simple site (PHP) that allows user changes (via jQuery) that modify elements' classes, and add/delete rows from a table.
I want to write these changes to the actual PHP file in question on the server every time a user makes a change, so that when the page is refreshed or revisited, the changes remain intact.
What's the simplest / best way to accomplish this? Thank you!
For addition/deletion of rows, fire ajax call and update records associated with the user. This is in addition to client-side (jQuery/JavaScript) changes to page. Whenever they revisit/refresh the page, data will be fetched from db, and as such will always be latest.
When you say that users modify elements' classes, I assume you mean their page's looks and styling (like some sites have on-page options to change background color, font-sizes). If that is the case, I suggest you:
Create a list of all possible states and store them in a new table in db, say display_options. You could store details like option_type (e.g. background color, font-size etc) and option_back_value (e.g. #FFF, #000 etc).
Create a new table say user_display_options where you store things like user_id, option_type and their chosen option_id.
While loading page, do a join on these tables using user_id. Then while creating your page, conditionally add classes etc to the page.
When user edits page, fire ajax call sending required data like user_id, option_type, option_id. As mentioned for other task, these changes to db will be in addition to client-side changes.
Also read #David 's comment to your question - it clears an important concept.

How to make hard-coded HTML entries saved as if entered in the UI of a CMS? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
I doubt I'm using the correct vocabulary (or tags) to explain what I'm looking for, but bear with me:
Eventually part of my page will have a section where things like list items and table data(<td>) can be entered/changed by logged in users. Let's say this is one of the <li>'s:
<!--template-->
<li><a title=""href=""><span></span></a></li>
So far my understanding is that if these entries are generated by a UI somewhere (à la Wordpress) these entries need(?) to be written in a database before becoming the generated page. Another thing I'm realizing is that the user of these CMS's doesn't automatically 'get' a copy of the generated page as source code.
What I would like to know is if it would be possible for me to make changes in HTML to this generated record/list inside notepad (I'll likely be messing with some other part of the page) and somehow have the site detect/record any changes as if they were entered through the UI?
Have PHP code create a file of the generated page
Have that page scanned for certain patterns/templates
Add the values found within the template to the DB, repeat
What language/approach could scan text and make database entries from its findings like how I'm describing? I just discovered sscanf(), but have no idea how to use it yet. I realize it's stupid to not just use the CMS, but the self-referential and text-scanning quality of it also interests me.
It sounds to me like you can implement a jQuery "Edit in Place" plug-in with a php script handler. I did something exactly this and their plug-in does all the heavy lifting, all you have to do is feed out the raw HTML with various clues about the table structure.
See this SO q/a... I used it to generate pages that displayed orders. Via editing in place, I made the orders (click-to-edit)-able. In the code, put everything in a foreach loop, then the jQuery links elements to the database through attributes like <tr id="<? echo $database_ID ?>"> to tie a row to a record and each <td> might have the database's column name as ID or a class name.
Let me preface this answer by saying it's almost certainly a bad idea, only tangentially relates to PHP, and creates at least as many problems as it solves. In particular, the security loopholes are terrible. But recently I saw an HTML form on a government website that reinvigorated my sense of humour about "lateral thinking", so just call me Pandora.
Theoretically you could implement something like this with a bit of Javascript and a cross-domain <form> post. In a nutshell, you would:
Create an HTML template with all of the tables, lists and other structures you require, plus a <form> containing a hidden input and a submit button. This template would be populated with data by the server application when the user initially requests a particular record.
Create a script for the template that parses the tables and lists for values (say, with DOM methods), serializes them (eg, into a JSON string), and sets the value of the form's hidden input to the serialized data.
Set the form's action attribute to a PHP script designed to deserialize the form data and persist it to a database. Also assign an event handler on the submit button that executes the serializer script before the form is posted.
Now, the trick here is in the user sequence. The user requests some record, which the server returns in a populated template. Ordinarily, a user would work with whatever CMS-style fields the template provides, but expiredninja instead saves the HTML source of the page, makes changes to the designated tables and lists, opens the modified HTML file in a browser, and clicks submit. The script serializes the data and the client posts the form to the server, which deserializes and saves the data.

Categories