serializearray() does not take form fields - php

I have index.php file which stores a form for user signup. But whenever I try to display data that is stored in the serializeArray it says that it is empty. Here is my code for the html form:
<form method="post" id="signupForm">
<div class="modal fade" id="signupModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="signupModalLabel">Sign Up</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="alert alert-danger" id="signupAlert" role="alert">
This is a danger alert—check it out!
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" placeholder="Username" maxlength="30">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" placeholder="Email address" maxlength="50">
</div>
<div class="form-group">
<label for="password">Choose a Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" maxlength="30">
</div>
<div class="form-group">
<label for="passwordConfirm">Confirm Password</label>
<input type="password" class="form-control" id="passwordConfirm" placeholder="Confirm Password" maxlength="30">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input class="btn btn-primary" name="signup" type="submit" class="btn btn-primary" value="Sign Up">
</div>
</div>
</div>
</div>
</form>
In my index.js I have a function to take all form fields entered and store them in serializeArray.
$("#signupForm").submit(function(event){
event.preventDefault();
var data = $(this).serializeArray(data);
console.log(data)
})
The array results shows that there are no values. I have tried to console log any string to see if I have correctly linked my index.js file to index.php and it works. There is only problem with getting form fields into the array.
[]length: 0 proto: Array(0)

Related

Adding a confirmation pop up when submitting record with laravel

I am making an add button and when clicked it brings up a modal where data can be entered but when clicked, this record gets sent through and to avoid mistakes, I wish to add a confirmation(yes or no) pop up to make sure the user is certain on submitting. Has anyone worked with this before?
Heres my modal code:
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Subject add</h5>
</div>
<form action="/test/save-subject" method="POST">
{{ csrf_field() }}
<div class="modal-body">
<div class="mb-3">
<label for="recipient-name" class="col-form-label">Subject ID:</label>
<input type="text" name="subjectcode" class="form-control" id="recipient-name" maxlength="6" style="text-transform:uppercase" required>
</div>
<div class="mb-3">
<label for="message-text" class="col-form-label">Description:</label>
<textarea name="detail" class="form-control" id="message-text" required></textarea>
</div>
<div class="mb-3">
<label for="recipient-name" class="col-form-label">Email Address:</label>
<input type="text" name="emailaddress" class="form-control" id="recipient-name" required>
</div>
<div>
<input type="checkbox" name="staff" value="1"> <label>Staff Update</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>

Login not working in php mysql code

I am trying to make the login page but I am not able to login to the form.
Code for form:
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Mentor Login</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post" action="">
<div class="form-group">
<label for="exampleInputEmail1">Email or Username</label>
<input type="text" class="form-control" name="email" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Email or Username">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" name="m_pass" id="exampleInputPassword1" placeholder="Password">
</div>
<div class="form-group">
<span class="psw">Forgot Password?</span>
</div>
<button type="submit" name="btn_log" class="btn btn-primary btn-block">Login</button>
<br>
<div class="form-group">
Don't have an Account?
<a class="btn btn-link" href="mentor_register.php">Create Account</a>
</div>
</form>
</div>
</div>
</div>
</div>
The code for the PHP:
if(isset($_POST['btn_log'])){
$m_pass = $_POST['m_pass'];
$usname = $_POST['usname'];
$sql = mysqli_query($con,"select * from mentor_reg where usname='$usname' AND m_pass='$m_pass'");
$check = mysqli_num_rows($sql);
if ($check == 1){
$_SESSION['login_ment']=$usname;
echo "<script>document.location.href='index.php';</script>";
}
else{
echo "<script>alert('Error password');</script>";
}
}
The form is submitting perfectly but users are not able to login. we have tried with both the username and password & email and password to check from database and trying to login. Thanks
First error:
<input type="text" class="form-control" name="email" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Email or Username">
Your input name is "email" and you are catching $_POST['usname'];
Your php code says
$usname = $_POST['usname'];
but this value is not sent from the from as you've given email in input field
<input type="text" class="form-control" name="email" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Email or Username">
Also can you post the errors please?

Is it possible to change the segment(3) which is the ID in my url into a random string(Codeigniter)?

I tried to change the $config['url_suffix'](that is located at my config/config) into $config['url_suffix'] = ''; . I encountered an error, it says that "Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster." And I also tried to put the random_string in my view, may update is not working now
Config file
$config['url_suffix'] = '<?= random_string(40?>';
View
<a data-toggle="modal" class="btn btn-warning" data-target="#update_account-<?= $profileAccount->id?>"><span class="glyphicon glyphicon-edit"></span>Edit</a>
<div class="modal fade" id="update_account-<?= $profileAccount->id?>" tabindex="-1" role="dialog" aria-labelledby="titleLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header modal-header-success">
<button type="button" class="close btn btn-primary" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="titleLabel">Update Profile</h4>
</div>
<div class="modal-body">
<div class="container">
<div clas="row">
<form method="post" action="<?= base_url(). 'User/updateProfile/'.random_string($profileAccount->id)?>">
<div class="col-md-5 col-lg-5">
<?= validation_errors();?>
<div class="form-group">
<label>ID</label>
<input type="text" disabled value="<?= $profileAccount->id?>" class="form-control">
</div>
<div class="form-group">
<label>First Name</label>
<input type="text" name ="fname"value="<?= $profileAccount->first_name?>" class="form-control">
</div>
<div class="form-group">
<label>Middle Name</label>
<input type="text" name ="mname" value="<?= $profileAccount->middle_name?>" class="form-control">
</div>
<div class="form-group">
<label>Last Name</label>
<input type="text" name ="lname" value="<?= $profileAccount->last_name?>" class="form-control">
</div>
<div class="form-group">
<label>Email Address</label>
<input type="email" name ="email" value="<?= $profileAccount->email?>" class="form-control">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name ="password" class="form-control">
</div>
<div class="form-group">
<label>Contact Number</label>
<input type="text" name ="phone" value="<?= $profileAccount->phone?>" class="form-control">
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<span class="pull-right">
<button type="submit" class="btn btn-success">Update Event</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</span>
</form>
</div>
</div>
</div>
</div>
Your config has missing character the closing parenthesis )
change this
$config['url_suffix'] = '<?= random_string(40?>';
to
$config['url_suffix'] = '<?= random_string(40)?>';
If not working I think your random_string function has an error

multiple popup form in a page some buttons connected using js i need a way for showing errors

VIEW::::
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content" id="cont">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Login</h4>
</div>
<div class="modal-body" id="outerbox">
<form method="post" action="<?php echo base_url('Login/client_login'); ?>">
<input type="email" name="email" id="box2" required="true" placeholder="Email"></input>
</br>
<input type="password" name="password" id="box3" required="true" minlength="6" placeholder="Password"></input>
<br/>
<button name="login_button" id="login_button">Login</button>
</form>
<button name="reg_button" id="reg_button" data-toggle="modal" data-target="#myModal1">Signup</button>
<p class="forgot">Forgot Password?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--vendor signin-->
<div id="ven_myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content" id="ven_cont">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<?php $error="";?>
<h4 class="modal-title">Login</h4>
</div>
<div class="modal-body" id="ven_outerbox">
<?php echo form_open(base_url('Login/vendor'));?>
<input type="email" name="email" id="ven_box2" required="true" placeholder="Email"></input>
</br>
<input type="password" name="password" id="ven_box3" required="true" minlength="6" placeholder="Password">
<button type="submit" name="ven_login_button" id="ven_login_button">Login</button>
<?php echo form_close();?>
<button name="ven_reg_button" id="ven_reg_button" data-toggle="modal" data-target="#ven_myModal1">Signup</button>
<p class="forgot pull-left">Forgot Password?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--client signup-->
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-content" id="cont1">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Signup</h4>
</div>
<div class="modal-body">
<div class="container">
<form method="post" action="<?php echo base_url(); ?>Signup/signup_client1">
<div id="s1" style="margin-top: 10px;">
<input type="text" name="first_name" class="sign-text" id="text1" required="true" placeholder="First Name"></input>
<input type="text" name="last_name" class="sign-text" id="text2" required="true" placeholder="Last Name"></input>
<input type="text" name="email" class="sign-text" id="text2" required="true" placeholder="Email"></input>
<input type="text" name="password" class="sign-text" id="text2" required="true" placeholder="Password"></input>
<input type="text" name="password1" class="sign-text" id="text2" required="true" placeholder="Re-Enter Password"></input>
<div>
<input type="submit" id="finish" value="Signup"></input>
</div>
</div>
</form>
<div id="my-signin2">
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark" data-width="120"></div>
</div>
<div class="fb-login-button" data-max-rows="1" data-size="xlarge" data-show-faces="false" data-auto-logout-link="false">
</div>
</div>
</div>
</div>
</div>
<!--vendor signup-->
<div id="ven_myModal1" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content" id="ven_cont1">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Signup</h4>
</div>
<div class="modal-body" id="ven_outerbox1">
<form method="post" action="<?php echo base_url(); ?>Signup/signup_vendor">
<input type="text" name="first_name" id="ven_box4" required="true" placeholder="First Name"></input>
</br>
<input type="text" name="last_name" id="ven_box5" required="true" placeholder="Last Name"></input>
</br>
<input type="email" name="email" id="ven_box6" required="true" placeholder="Email"></input>
</br>
<input type="text" name="password" id="ven_box7" minlength="6" required="true" placeholder="Password"></input>
<!-- <input type="text" name="pass2" id="ven_box7" required="true" placeholder="Re-enter Password"></input> -->
<button type="submit" name="ven_reg1_button" id="ven_reg1_button">Signup</button>
<button name="ven_login1_button" id="ven_login1_button">login</button>
</form>
<div id="my-signin2">
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark" data-width="120"></div>
</div>
<div class="fb-login-button" data-max-rows="1" data-size="xlarge" data-show-faces="false" data-auto-logout-link="false">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
This is my view file i need a best way to output the validation errors and incorrect id/password errors whenever i try to use flashdata it redirects to homepage but the form doesnt pops up so i need a perfect way.I dont have much knowledge in javascript but i used alert method for showing errors but somewhere it stuck and page became unresponsive i used alert method in my controller file

Form in Bootstrap modal not posting PHP values to another page

I am using a form in a bootstrap modal window to post data to another page. However when i try to print the post values on the other page all I am getting is an empty array.
Here's my modal code:
<div class="modal hide" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
X</button>
<h3 id="myModalLabel">
Enter your Credentials</h3>
</div>
<div class="modal-body">
<form id="modal-form" class="form-horizontal" accept-charset="UTF-8" method="POST" action="login.php" data-remote="true">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="email" id="email" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="passwd" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<input type="submit" class="btn btn-primary" value="Submit"/>
Sign up
</div>
</div>
</form>
</div>
</div>
Here's the command I'm giving in login.php:
echo "Email is:";
echo $_POST["email"];
echo "Password is:";
echo $_POST["passwd"];
However all I'm getting is an empty array.
Is there some sort of special way I'm supposed to do this?
You have't define name in input just change two line from your code. add name of that input.
<input type="email" id="email" name="email" placeholder="Email" />
<input type="password" id="passwd" name="passwd" placeholder="Password" />

Categories