Lemex
Lemex

Reputation: 3804

PHP Userfriendly/Smart Forms (Without JS)

Im currently trying to develop a form that can work fully without JavaScript.

Basicly i want the user to be able to do the following:

I was thinking of doing the following for example:

<input type="text" value="<?php checkPost(name);?>"/>

Then in check post doing something like:

function checkPost($name){
    try{
       return  $_POST[name];
    }
    catch{
        return "";
    }
}

Would this stop the error:

Notice: Undefined index

Which means if the data wasnt posted then just set the value to "" but if it was posted then set the old value to it.

Is this the best way to do it can anyone tell me a smarter way to do this with my forms.

My form markup can be seen here: JS Fiddle

Upvotes: 0

Views: 421

Answers (1)

Bogdan Burym
Bogdan Burym

Reputation: 5512

It will not stop error.
Because error is not an Exception in this case.

This sounds much better:

function checkPost(name){
    return isset($_POST['name']) ? $_POST['name'] : '';
}

My opinion - it is very bad idea to write validation functions for each for field.
Read about Zend_Form.
You can include it in your project even if you are not using ZF.

Upvotes: 1

Related Questions