?
Solved

using same form for add and edit in php

Posted on 2014-11-07
3
Medium Priority
?
285 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
[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
3 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1000 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 49

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 111

Assisted Solution

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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

770 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