Solved

using same form for add and edit in php

Posted on 2014-11-07
3
176 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 82

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 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

17 Experts available now in Live!

Get 1:1 Help Now