Need to make changes to Job Form

These are more along the lines of requests than issues:

1. I want to make it possible for non-logged in users to post a job. I had edited out the login check in the php page but then an "undefined" message came up under each field when filled in. Ideally, a non-logged in user would be able to fill out the form but also register at the same time. Form details would not be submitted until registration is complete. How could I do this?

2. Your form fields are created in a complex manner. Quite impressive coding. But what happens if I need to add fields or make some fields optional instead of required? How can I accomplish this?

  • Vinod Dalvi

    Hi @Andrew,

    I hope you are well today and thank you for your question.

    1. I want to make it possible for non-logged in users to post a job. I had edited out the login check in the php page but then an "undefined" message came up under each field when filled in. Ideally, a non-logged in user would be able to fill out the form but also register at the same time. Form details would not be submitted until registration is complete. How could I do this?

    I have tested it on my test site and found the form fields are displaying undefined javascript error message on validating the field.

    I just did quick troubleshooting and found this is happening because due to some reason the AJAX function ajax_validate is returning status value as 0 instead of 1 which is causing this issue.

    2. Your form fields are created in a complex manner. Quite impressive coding. But what happens if I need to add fields or make some fields optional instead of required? How can I accomplish this?

    I don't think this is possible out of the box without complex custom coding. I have notified the plugin developer to get his valuable reply here regarding this.

    Thanks,
    Vinod Dalvi

  • Hoang Ngo

    Hi @Andrew,

    I hope you are well today and thanks for your question.

    1. I want to make it possible for non-logged in users to post a job. I had edited out the login check in the php page but then an "undefined" message came up under each field when filled in. Ideally, a non-logged in user would be able to fill out the form but also register at the same time. Form details would not be submitted until registration is complete. How could I do this?

    The Ajax process for now, is only for logged in user, if user still not login, the value return is 0.
    You can always custom coding the scenario for non-logged in user, here is an example how to create new job, validate, and get the id & job link after save.

    add_action('wp_ajax_nopriv_job_save', 'save_je_job');
    function save_je_job()
    {
        //process create new user code here
        //assume the process is done, and $user_id = 1;
        $user_id = 1;
        //insert new job
        $model = new JobsExperts_Core_Models_Job();
        //assume the data is contain all
        $data = $_POST['JobsExperts_Core_Models_Job'];
        //import the post data to model property
        $model->import($data);
        $model->owner = $user_id;
        //validate the data
        if ($model->validate()) {
            $model->save();
        }
        //getting new job id
        $id = $model->id;
        //link to the new job
        $link = get_permalink($id);
        //the rest code doing here
    }

    2. Your form fields are created in a complex manner. Quite impressive coding. But what happens if I need to add fields or make some fields optional instead of required? How can I accomplish this?

    Currently, this is a little bit out of the box. You will need to modify the plugin, I will have a plan for making the component more de-couple in future release.
    For now, about the validation, you will need to update the code here
    /jobs-plus/modules/JobsExperts/Core/Models/Job.php
    I assume you have a programming background, for the validation rules, you will need to check this function, in same file.

    public function rules()
        {
            $rules = array(
                array('required', 'job_title,contact_email,dead_line,open_for,description'),
                array('email', 'contact_email'),
            );
            if (JobsExperts_Plugin::instance()->settings()->job_budget_range == 1) {
                $rules[] = array('required', 'min_budget,max_budget');
                $rules[] = array('numeric', 'min_budget,max_budget');
            } else {
                $rules[] = array('required', 'budget');
            }
    
            return $rules;
        }

    You will see the $rules variable, this variable hold the validate rules for Job properties, the format is
    array('rule_name','properties name, separate by commas')
    So from now, you can update the validation rules for your scenario.
    For the form, you can check here, /jobs-plus/modules/JobsExperts/Core/Shortcode/JobForm.php
    The function you need to modify is shortcode(), in line 75.

    If you need any information about the coding, please don't hesitate to let us know so we can assist

    Best regards,
    Hoang Ngo

  • Andrew

    Hi @Hoang Ngo,

    I just wanted to clarify one thing before I implement the change.

    Would I add the first set of code to the theme functions.php or to the functions for the J&E plugin?
    [add_action('wp_ajax_nopriv_job_save', 'save_je_job'); ...etc etc]

    I'm thinking of saving the data in a session and then allowing the user to sign up before the form is finally submitted. Let me know if that is possible with the changes you have recommended.

    Thanks is advance.

  • Hoang Ngo

    Hi @Andrew,

    I hope you are well today and thanks for your question.

    Would I add the first set of code to the theme functions.php or to the functions for the J&E plugin?
    [add_action('wp_ajax_nopriv_job_save', 'save_je_job'); ...etc etc]

    WordPress is very flexible, you can add it anywhere except the plugin folder, or it can be removed when you upgrade the plugin.

    I think the best is you can create a new plugin, and place you code there :slight_smile:

    I'm thinking of saving the data in a session and then allowing the user to sign up before the form is finally submitted. Let me know if that is possible with the changes you have recommended.

    WordPress does not use sessions in any way at all. So I think sessions is not a really good way to go. I think you can create a new table, for storing temp data, and make a cronjob to clean up that table in an amount of time. This way, you can get benefit in the scenario when user doing on the form, for some reason, they stop it, and then when they come back, then we can still get the data and let the user continue, if using session, that data will be lost.

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang Ngo

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.