Welcome Guest, Not a member yet? Register   Sign In
[HELP] Form submitted even when empty.
#1

(This post was last modified: 11-20-2018, 09:20 PM by HarrysR.)

Hello, 
i have the following really serious problem with my register form. Here's the thing.
I use jquery to load the register url in a div.
Everything's ok so far.

The BIG problem is that when i click submit, the form is submited and the ajax function is executed even if the inputs are empty. More over the field is filled with the action attributed even if i have it empty in my code.

Here's the modal code (I pasted in pastebin cause its kinda big):
https://pastebin.com/AdEpyAci

Note: As you can see the attribute value is blank, but the form is still submitted.

Model:
Code:
public function register($enc_password){
   $user_name = convert_accented_characters($this->input->post('screenNameInput'));
   $user_name_slug = url_title($user_name);
   $data = array();
   $contact_data = array();
   $data['user_group_id'] = $this->input->post('userGroupInput');
   $data['screen_name'] = $this->input->post('screenNameInput');
   $data['email'] = $this->input->post('email');
   $data['password'] = $enc_password;
   $data['slug'] = $user_name_slug;
   $data['city_id'] = $this->input->post('cityInput');
   $data['register_status'] = 1;
   $data['unique_id'] = random_string('numeric', 6);
   if ( $this->input->post('userGroupInput') == 1 && $this->input->post('websiteInput') ) {
     $data['website'] = $this->input->post('websiteInput');
   }

   $user_created = $this->db->insert('users', $data);
   if ($user_created) {
     $user_id = $this->db->insert_id();

     $contact_data['primary_num'] = $this->input->post('phoneInput');
     $contact_data['info_group_name'] = $this->input->post('screenNameInput');
     $contact_data['city'] = $this->input->post('cityInput');
     $contact_data['to_user_id'] = $user_id;

     $registered = $this->db->insert('contact_info', $contact_data);
     if ($registered) {
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }

 }


Controller:
Code:
 public function create_user(){
   if (count($_POST) > 0 && !$this->input->post('name')) {
     $pass = $this->input->post('name');
     $email = trim($this->input->post('email'));
     $email_exist = $this->user_model->check_email_exist($email);
     if ($email_exist) {
       $result['status'] = 'failed';
       $result['message'] = '<div class="w-100 text-center bg-danger text-white py-1 mb-2">' . $this->lang->line('error_email_exist') . '</div>';
     } else {
       //Pass enc
       $enc_password = md5($this->input->post('passInput'));
       $register = $this->user_model->register($enc_password);
       if ($register) {
         $result['status'] = 'success';
       } else {
         $result['status'] = 'failed';
         $result['message'] = 'Please fulfil the empty inputs';
       }
     }
   } else {
     $result['status'] = 'failed';
     $result['message'] = '<div class="w-100 text-center bg-danger text-white py-1 mb-2">Something went wrong! Please check your form inputs.</div>';
   }
   echo json_encode($result);
 }

It just drives me crazy.. The thing is that even though the input data are required, if they're empty the user can still register and have an empty - not valid profile url and empty data submitted in the db..

Any ideas? Thank you!

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply


Messages In This Thread
[HELP] Form submitted even when empty. - by HarrysR - 11-20-2018, 09:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB