Viewing 5 replies - 1 through 5 (of 5 total)
  • What are you using to create the form? Are you using a plugin or are you building this form out yourself?

    Thread Starter jay1987

    (@jay1987)

    Ive built it myself to a certain degree however other parts are with the CRM company, what i am trying to do is add it so that the fields are mandatory before submission.

    Ill be honest and im not hundred percent certain the best way to achieve this in php without affecting the entire workings .

    Thread Starter jay1987

    (@jay1987)

    if (isset($_REQUEST[‘submit’]) && isset($type) && isset($parentId)) {

    $name = $_POST[“names”];
    echo ‘$name is set even though it is empty’;
    $country = $_POST[“country”];

    $gender = $_POST[“gender”];

    $age = $_POST[“age”];

    $email = $_POST[“email”];
    echo ‘$email is set even though it is empty’;

    Doesnt work.

    Well whatever you do, make sure to wrap your stuff up in your own namespace so you you can minimize function conflicts with WordPress!

    Anyway back to your issue – if most of your users are using JavaScript, you can basically hide the submit button until the appropriate fields are filled in. Pros: easy to implement. Cons: not foolproof and there may be accessibility issues.

    Or you can do the standard form validation approach where after the submit button is hit, the form data goes through a validation process. If all the required fields are filled in correctly (and the data input is good – always make sure to check this if you’re going to be inserting this data into any database or used anywhere else on the site) then the real submission script fires off and actually submits the data. Otherwise, error message to the user. A good basic example of form validation can be found here: https://www.sitepoint.com/form-validation-with-php/

    Please note that form validation is pretty complex – it is almost always a better idea to use an existing form validation library then to build your own. Finally, if at all possible, I’d recommend searching for some WordPress plugins that can help you build a form, provide form validation, and tie in nicely within WordPress itself.

    Thread Starter jay1987

    (@jay1987)

    Thank you Bemdesing, I shall look into this further.

    With Regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Making form mandatory to fill in to submit’ is closed to new replies.