nodster Posted May 30, 2007 Share Posted May 30, 2007 Hi there, In HTML forms you use the 'required-value' to ensure that a field is completed before submission, is there any way to do this check in PHP? If so could you please give me an example or a link to where to find it. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/53542-how-do-you-get-required-fields-in-php/ Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 <?php if(!isset($_POST["variable"]) || empty($_POST["variable"])) { // If $_POST["variable"] isn't set, or is empty... die("You didn't fill in the required field"); // Die } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53542-how-do-you-get-required-fields-in-php/#findComment-264573 Share on other sites More sharing options...
kenrbnsn Posted May 30, 2007 Share Posted May 30, 2007 If you want to check the contents before the user submits the form, this can not be done via PHP, since PHP doesn't see the data until after the form is submitted. This can only be done with Javascript, as far as I know. Ken Quote Link to comment https://forums.phpfreaks.com/topic/53542-how-do-you-get-required-fields-in-php/#findComment-264582 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.