Jump to content

Recommended Posts

no !!!! ;D

 

you can put all your required field in an array then loop it to see it it is set

 

eg...

//note this should be the name of the fields

$required = array('chkname','dropage','teng',etc...)

 

then loop your array

 

foreach($required  as $val){

    if (isset($_POST[$val])){

        ++$count;

        $missing .=$val;

    }

}

echo $count. $missing;// ;D

 

 

Link to comment
https://forums.phpfreaks.com/topic/74812-solved-validation/#findComment-378281
Share on other sites

PHP is a server-side script, which means that to check the validity of any input, the whole form must be sent in to be processed. Another part of the script (or a different script) then checks all of the input data. If an error exists, the form must be sent back to the client for update. There are several techniques for doing this cleanly.

 

Javascript is a client-side script, which means it can check form input on-the-fly while it's in the browser. It can generate errors in real-time and refuse to send the script to the server until it's satisfied.

 

So you need to choose which way you want to go here... there are TONS of Javascript routines that you can download and play with. If you need help with using PHP to check your forms, let us know!

 

BTW, you can also use AJAX to accomplish this, but that might be a bit advanced for your level right now.

 

PhREEEk

Link to comment
https://forums.phpfreaks.com/topic/74812-solved-validation/#findComment-378400
Share on other sites

That rather depends on what validation you wish to do. If you are simply wanting to check if anything has been put into the fields, then using the empty() function would suffice. As was suggested, you could place all of the post fields into an array, and loop through, checking each in turn.

 

There are plenty of other validation techniques you might want to use. Perhaps you want to check the length of certain fields? Try the strlen() function. Perhaps you want to check the form of certain strings (email addresses for example). If so, you'll need to use regular expressions. There's a forum on this site for those, so take a look there.

 

The point im trying to make is that there's no set rules for this. It all depends on the specific situation - you'll need different validation rules for different things.

Link to comment
https://forums.phpfreaks.com/topic/74812-solved-validation/#findComment-378513
Share on other sites

The first thing to do is the HTML for the form, so that you can capture the data to begin with. You can't process anything in PHP until it exists and is sent in for processing.

 

If you are not thoroughly versed in HTML forms, you might want to become familiar with a 'help' site and use their examples to guide you. Point is, there are form properties that you can set that will allow you to control the data a little bit up front, before it is processed. You need to make decisions here... For example, if any data is completely predictable or stringent, we would want to offer those choices in a drop-down or radio button configuration versus a standard input box where they can type in anything. Allowing the choice of two or more options in the same field also dictates a certain direction to go.

 

Creating the Form is in fact an artform unto itself, and should be considered 100% independent of the processing stage.

 

So let's get you started there... get your form 100% setup. Post any questions or code here. Having the form properly setup up front will save you processing time when it comes time to check the data.

 

PhREEEk

Link to comment
https://forums.phpfreaks.com/topic/74812-solved-validation/#findComment-378637
Share on other sites

Ok, please post the form HTML, or if you prefer one-on-one help with a little less side-chatter, feel free to PM me.

 

If you post it in this thread, please tell us how you want each field validated, or if you just simply want to verify that something has been put into each field (not very safe, of course...).

 

PhREEEk

Link to comment
https://forums.phpfreaks.com/topic/74812-solved-validation/#findComment-379080
Share on other sites

Thanks for marking this as 'solved' for the original poster, but there are other things to be considered, such as how she wants errors handled, and how the form should go back to the client (with correct form fields pre-filled in, or starting from scratch). There are details... (assuming she wants a nice form and not a hack).

 

I'll wait to hear from the OP.

 

PhREEEk

Link to comment
https://forums.phpfreaks.com/topic/74812-solved-validation/#findComment-379093
Share on other sites

is there a simple code that will check to see if users have filled in required fields on a form?

Thanks for marking this as 'solved' for the original poster, but there are other things to be considered, such as how she wants errors handled, and how the form should go back to the client (with correct form fields pre-filled in, or starting from scratch). There are details... (assuming she wants a nice form and not a hack).

 

I'll wait to hear from the OP.

 

PhREEEk

 

read the tread  :D

it sould be another topic

Link to comment
https://forums.phpfreaks.com/topic/74812-solved-validation/#findComment-379095
Share on other sites

is there a simple code that will check to see if users have filled in required fields on a form?

Thanks for marking this as 'solved' for the original poster, but there are other things to be considered, such as how she wants errors handled, and how the form should go back to the client (with correct form fields pre-filled in, or starting from scratch). There are details... (assuming she wants a nice form and not a hack).

 

I'll wait to hear from the OP.

 

PhREEEk

 

read the tread  :D

it sould be another topic

 

I can read fine, thanks. I was offering extended help, and also offered for the OP to Private Message me directly if she wanted further help.

 

YOU should learn to read better.

 

PhREEEk

Link to comment
https://forums.phpfreaks.com/topic/74812-solved-validation/#findComment-379098
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.