Skip to main content
August 8, 2006
Question

If error submit can I use php & it returns with kept details?

  • August 8, 2006
  • 22 replies
  • 1258 views
Hi I was wondering if using php I can check the registration form for errors e.g. not filled out when required and upon return they can still have the details they already submitted still there so they don't have to re-fill the form.
Thanks for you help.
This topic has been closed for replies.

22 replies

September 30, 2006
Crickey I give up I think I will have to use javascript.
I have honestly been trying everything possible. I have gone to so many forums and read so many books and everything I try won't work with dreamweaver mx 2004. I have tried some of the code on a normal php page without dreamweaver input and it works but for the life of me I can't get the form to return and with input or errors.
Does anybody know how to trick dreamweaver to allow me to place the conditional data in the insert form?
The update record is ok because it already has input.
Hope somebody knows how to actually have the form return, thanks. this is the last part of my web design program.
Sorry to be a pain if I am taking so long to understand.
September 14, 2006
Hi thanks guys I have been trying ideas and but I don't seem to be having any success with the form returning with the fields to be filled. So I am thinking I need to do this:
Somewhere above the form to place a
if(isset($_POST['send']))
{
$formfield = $_POST[''];
$formfield['Name'] || $formfield['Address'] || $formfield['Phone']
} else if(trim($formfield) == '')
{
echo ' You need to fill this section please'
}
; ?>

Where send is the name of the form button - submit.
I figure I need to place trim() to preserve white space but not sure if its needed.

I also have a search text field that works really well but with using $_GET and need to have it return so that the user actually places a search word.
I can do all of these forms with the javascript script I have but I want to learn how to hard code this using php in case someone has javascript turned off.

Sometimes when I try these conditionals I am getting testing server errors with dreamweaver.
Hope this makes sense above, I am sure it will finally sink in.

Also one last question, just regarding sequence of events with code on the page. Is this the appropriate way -
1: Connection
2: Session Start
3: Restrict Access or Log In Behaviour
4: Log Out Behaviour
5: All recordsets
6: Conditional Form Data
7: Email To ? On Form Submission
8: Insert/Update Form Data
9: The Actual Form

Just want to make sure I am placing it all in the right way. I am not sure whether it makes a difference or not.
Thanks - many questions.
Inspiring
September 7, 2006
Thanks....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:edp05q$t4j$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> Is there any real difference (other than the letter count) in using
>> array_key_exists() and isset()?
>
> I don't think so. As you will know from my books, I tend to use
> array_key_exists() to control the code that runs after a form has been
> submitted. It's a technique that I have used for several years, so I stick
> with it. Using isset() should work equally well.
>
> What I find unnecessarily complicated about the code you suggest is not so
> much the use of array_key_exists(), but the use of the conditional
> operator. Although I tend to use the conditional operator quite frequently
> myself, I remember that it took me a long time to understand what it
> meant. When teaching beginners, using if... else is much easier for them
> to understand. In the case of form validation, you rarely need to have a
> default value for a text field, so if (isset($_POST['whatever'])) is all
> you need.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Inspiring
September 7, 2006
Murray *ACE* wrote:
> Is there any real difference (other than the letter count) in using
> array_key_exists() and isset()?

I don't think so. As you will know from my books, I tend to use
array_key_exists() to control the code that runs after a form has been
submitted. It's a technique that I have used for several years, so I
stick with it. Using isset() should work equally well.

What I find unnecessarily complicated about the code you suggest is not
so much the use of array_key_exists(), but the use of the conditional
operator. Although I tend to use the conditional operator quite
frequently myself, I remember that it took me a long time to understand
what it meant. When teaching beginners, using if... else is much easier
for them to understand. In the case of form validation, you rarely need
to have a default value for a text field, so if
(isset($_POST['whatever'])) is all you need.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Inspiring
September 7, 2006
> Personally, I think that the code Murray gave you is unnecessarily complex
> for this scenario.

<input name="firstname" type="text" id="firstname" value="<?php
echo(array_key_exists('firstname',$_POST))?$_POST['firstname']:'Enter Your
First Name'); ?>">

There's no doubt! It's home-grown.... 8)

You recommend this -

<input value="<?php if (isset($_POST['first_name'])) {
echo $_POST['first_name'];} ?>" type="text" name="first_name"
id="first_name" />

Is there any real difference (other than the letter count) in using
array_key_exists() and isset()?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:edoo03$k40$1@forums.macromedia.com...
> jjjhbj111 wrote:
>> Thanks for the help. Sorry David I don't use Dreamweaver8 and still on
>> php4.
>
> The necessary code needs to be inserted by hand or using the Server
> Behavior Builder, which is also in MX 2004 (and possible MX, too). The
> code involved is compatible with both PHP 4 and PHP 5.
>
>> So I gather I will need to set up a variable $error first but do I still
>> use key_array_exists()
>
> Personally, I think that the code Murray gave you is unnecessarily complex
> for this scenario. Follow the pattern that I gave you and test it to see
> how it works.
>
> If you're still at the beginning stages of PHP, you would probably get a
> lot out of my book, even if you're using MX 2004. Chapters 5 and 6 are
> devoted entirely to hand coding, and most of the Dreamweaver server
> behaviors are common to MX 2004 and DW8.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Inspiring
September 7, 2006
jjjhbj111 wrote:
> Thanks for the help. Sorry David I don't use Dreamweaver8 and still on php4.

The necessary code needs to be inserted by hand or using the Server
Behavior Builder, which is also in MX 2004 (and possible MX, too). The
code involved is compatible with both PHP 4 and PHP 5.

> So I gather I will need to set up a variable $error first but do I still use
> key_array_exists()

Personally, I think that the code Murray gave you is unnecessarily
complex for this scenario. Follow the pattern that I gave you and test
it to see how it works.

If you're still at the beginning stages of PHP, you would probably get a
lot out of my book, even if you're using MX 2004. Chapters 5 and 6 are
devoted entirely to hand coding, and most of the Dreamweaver server
behaviors are common to MX 2004 and DW8.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
September 7, 2006
Thanks for the help. Sorry David I don't use Dreamweaver8 and still on php4.

So I gather I will need to set up a variable $error first but do I still use key_array_exists()
Sorry for being a noob I am very slowly learning php and mysql.
I would love to learn much quicker.
Thanks again
Inspiring
September 6, 2006
jjjhbj111 wrote:
> What I want to do is validate the form on submit but being able to have the
> form returned filled out with the correct items but give error for those not
> filled out.

The code that Murray gave you does that. The first time you load the
page, it displays "Enter your first name". When you submit the form, it
displays whatever was inserted into that field.

The principle of validation is quite simple, but it involves quite a bit
of coding. Basically, you create a self-processing form (one that
submits to the same page), which checks the contents of the $_POST
array. If any items are incomplete, the details are stored in an array
called $error or $missing, and the page is redisplayed with the existing
details already filled out. Otherwise the form is processed as normal.

I show how to do this in "Foundation PHP for Dreamweaver 8", which also
shows you how to create server behaviors of your own to automate the
create of the code. However, the code itself is simple:

<input value="<?php if (isset($_POST['first_name'])) {
echo $_POST['first_name'];} ?>" type="text" name="first_name"
id="first_name" />

You need to do that for every form field, which is why creating a custom
server behavior is quite useful.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
September 6, 2006
Hi thanks guys I have tried this again but it doesn't help with validating the form, it only gives me the 'Enter Your First Name' in the text box and that is it.
What I want to do is validate the form on submit but being able to have the form returned filled out with the correct items but give error for those not filled out.
I have a javascript already but if someone may have javascript turned off and I want to try and prevent someone tampering with the form. I am wanting to learn how to accomplish this. I will have many types of forms on my site.
Any other suggestions are greatly appreciated.
Thanks
Inspiring
August 10, 2006
jjjhbj111 wrote:
> array_key_exists is a new term for me. I just read about it.
> Now will I have to use anything with the submit button to return the form for
> this process or will php take care of that as is?

PHP takes care of it.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
August 11, 2006
Thank you I will try it out now.