Solved

using same form for add and edit in php

Posted on 2014-11-07
3
183 Views
Last Modified: 2014-11-17
Hi

I usually use the same form in php for add and edit. If the form is for add i leave the fields empty and change the button text to add. If the page if for edit i populate it with appropriate values from the database and change button text to update. There may be some other minor tweaks too. However I have been reading around and saw this

"http://stackoverflow.com/questions/6657331/add-view-edit-mysql-entries-with-the-same-php-form"

"It's generally quite easy to use the same form. Another question is how you solve validation errors and not making the user re-fill the form - this gets solved as in the same process. You'll need some helpers for the select fields and any checkbox/radio fields. Exactly how much the helpers do is up to you, but these will get you started:"

I dont know what this means. Why do i need helped? If the user changed a select or radio button on an edit then the form validation would pick it up wouldnt it if there was a problem

If there is a simple design pattern for using the same form for adds/updates I would be grateful if you could point me to it

thanks
0
Comment
Question by:andieje
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 40429664
I often do it the way you do.  I would ignore that page from Stackoverflow, there is a lot missing from their code examples.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40429689
You also need to consider the quality measures of that page
it is 3 years old
There is no accepted answer
there are only 2 responses
there is only one upvote (in 3 years)

not all web pages are of a high quality :(
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 40429825
HTML Form processing is discussed here:
http://php.net/manual/en/tutorial.forms.php

There is no single, simple way to handle text inputs, radio buttons and check boxes.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_5450-Common-Sense-Examples-Using-Checkboxes-with-HTML-JavaScript-and-PHP.html

Table maintenance is a fairly advanced concept in PHP and MySQL.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12335-PHP-and-MySQLi-Table-Maintenance.html

A sensible design pattern using MySQL might take advantage of the MySQL-only REPLACE INTO statement.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

930 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

12 Experts available now in Live!

Get 1:1 Help Now