form_validation->set_rules() not working properly in code igniter - php

Im new to code igniter and trying to build a login and registration form in code igniter. So far login is ok but the registration form does not provide as it is needed. I followed a video tutorial but it didnt work out well. when i manually debug the code i realized that $this->form_validation->set_rules() is not working.
please help me out.
The view
<form action="<?php echo base_url();?>LoginController/Register" method="get">
<p><span id="sprytextfield1">
<label for="tn">Full Name</label>
<input class="form-control" input type="text" name="full_name" placeholder="Please Enter Your Full Name" style="width:50%" ><?php echo form_error('full_name'); ?>
<span class="textfieldRequiredMsg"> </span></span> <span id="sprytextfield2">
<label for="tjt">Designation <?php echo form_error('des'); ?><br>
<br>
<input type="radio" name="des" value="pm">
Project Manager
<input type="radio" name="des" value="ceo">
CEO<br>
<input type="radio" name="des" value="dev">
Devoloper </label>
</span></p>
<p><span> <span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield3">
<label for="te">Email</label>
<input class="form-control" input type="text" name="email" placeholder="Please Enter Your Email" style="width:50%" ><?php echo form_error('email'); ?>
<span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield4">
<label for="tc">Company</label>
<input class="form-control" input type="text" name="company" placeholder="Please Enter Your Company Name" style="width:50%" ><?php echo form_error('company'); ?>
<span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield5">
<label for="tun">User Name</label>
<input class="form-control" input type="text" name="user_name" placeholder="Please Enter Your User Name" style="width:50%" ><?php echo form_error('user_name'); ?>
<span id="sprytextfield6">
<label for="tpw">Password</label>
<input class="form-control" input type="password" name="password" placeholder="Please Enter Your Password" style="width:50%" ><?php echo form_error('password'); ?>
<span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield7">
<label for="tpw2"> Confirm Password</label>
<input class="form-control" input type="password" name="cpassword" placeholder="Please Re Enter Your Password" style="width:50%" ><?php echo form_error('cpassword'); ?>
<span class="textfieldRequiredMsg"></span></span> </p>
<table width="385" cellspacing="50px">
<tr>
<th width="75"> <button type="submit" class="btn btn-lg btn-primary"method="post">Create Account</button>
</th>
<th width="154"> <input name="Reset" type="reset" class="btn btn-lg btn-primary" >
</th>
</tr>
</table>
<p> </p>
</form>
The controller
function Register(){
$this->load->library('form_validation');
$this->load->helper(array('form', 'url'));
//Validation Rules
$this->form_validation->set_rules('full_name','Full Name','trim|required');
$this->form_validation->set_rules('email','Email Address','trim|required|valid_email|callback_check_mail_Exists');
$this->form_validation->set_rules('company','Company','trim|required');
$this->form_validation->set_rules('user_name','Username','trim|required|min_length[4]|callback_check_user_Exists');
$this->form_validation->set_rules('password','Password','trim|required|min_length[8]');
$this->form_validation->set_rules('cpassword','Password Confirmation','trim|required|matches[password]');
$this->form_validation->set_message('check_user_Exists', 'Username already exists. Please select another');
$this->form_validation->set_message('check_mail_Exists', 'E-mail already registerd.');
if($this->form_validation->run()==false){
$this->load->view('SignUp');
}else{
$this->load->model('MembershipModel');
if($this->MembershipModel->create_member()){
$data['account_created']='Your account has been created <br/><br/>';
$this->load->view('loginform',$data);
}else{
$this->load->view('SignUp');
}
}
}
the model
function create_member(){
$username=$this->input->post('user_name');
$new_member=array(
'full_name' => $this->input->post('full_name'),
'e-mail' => $this->input->post('email'),
'company' => $this->input->post('company'),
'user_name' => $this->input->post('user_name'),
'pwd' => md5($this->input->post('password')),
'designation' => $this->input->post('des')
);
$insert=$this->db->insert('user',$new_member);
return $insert;
}
function check_mail_Exists($email){
$this->db->where('e-mail',$email);
$result=$this->db->get('user');
if($result->num_rows>0){
return false;
}else{
return true;
}
}
please help me out

put method="post" in your view files

Try this
view
<!-- <form action="<?php// echo base_url();?>LoginController/Register" method='get'> -->
<?php echo form_open(base_url('LoginController/Register'),['method'=>'post'])?>
<p><span id="sprytextfield1">
<label for="tn">Full Name</label>
<input class="form-control" input type="text" name="full_name" placeholder="Please Enter Your Full Name" style="width:50%" ><?php echo form_error('full_name'); ?>
<span class="textfieldRequiredMsg"> </span></span> <span id="sprytextfield2">
<label for="tjt">Designation <?php echo form_error('des'); ?><br>
<br>
<input type="radio" name="des" value="pm">
Project Manager
<input type="radio" name="des" value="ceo">
CEO<br>
<input type="radio" name="des" value="dev">
Devoloper </label>
</span></p>
<p><span> <span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield3">
<label for="te">Email</label>
<input class="form-control" input type="text" name="email" placeholder="Please Enter Your Email" style="width:50%" ><?php echo form_error('email'); ?>
<span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield4">
<label for="tc">Company</label>
<input class="form-control" input type="text" name="company" placeholder="Please Enter Your Company Name" style="width:50%" ><?php echo form_error('company'); ?>
<span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield5">
<label for="tun">User Name</label>
<input class="form-control" input type="text" name="user_name" placeholder="Please Enter Your User Name" style="width:50%" ><?php echo form_error('user_name'); ?>
<span id="sprytextfield6">
<label for="tpw">Password</label>
<input class="form-control" input type="password" name="password" placeholder="Please Enter Your Password" style="width:50%" ><?php echo form_error('password'); ?>
<span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield7">
<label for="tpw2"> Confirm Password</label>
<input class="form-control" input type="password" name="cpassword" placeholder="Please Re Enter Your Password" style="width:50%" ><?php echo form_error('cpassword'); ?>
<span class="textfieldRequiredMsg"></span></span> </p>
<table width="385" cellspacing="50px">
<tr>
<th width="75"><button type="submit" class="btn btn-lg btn-primary">Create Account</button></a>
</th>
<th width="154"> <input name="Reset" type="reset" class="btn btn-lg btn-primary" >
</th>
</tr>
</table>
<p> </p>
</form>

Related

Failure receiving POST results in PHP/HTML

I've done tests and it's definitely not a problem with the database, it connects fine and variables input if specified, (the integers work). Note that the {} brackets around the variables in the sql statement, for some reason need to be there for it to work, if someone could tell me why that'd be great.
The main problem is the POST for receiving from the form, nothing echoes, nor inputs to the database. Can anyone help? Thanks in advance.
PHP:
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$username = $_POST['username'];
$pw = $_POST['pw'];
$email = $_POST['email'];
$wins = 0;
$losses = 0;
$played = 0;
$earnings = 0;
$sql = "
INSERT INTO users (first_name, last_name, username, password, email, last_login, date_joined, wins, losses, played, earnings) VALUES
('{$firstName}','{$lastName}','{$username}','{$pw}','{$email}','1111','2222','{$wins}','{$losses}','{$played}','{$earnings}')
";
if(!mysql_query($sql, $con)){
echo 'Worked';
} else {echo 'Failed';}
HTML:
<form id="registration_form" action="http://valhq.com/register/" method="POST">
<div class="signup_form_content_names">
<div class="signup_form_input_fn">
<input type="text" class="signup_input_style_fn" id="firstName" placeholder="First Name" maxlength="20">
</div>
<div class="signup_form_input_ln">
<input type="text" class="signup_input_style_ln" id="lastName" placeholder="Last Name" maxlength="20">
</div>
</div>
<div class="signup_form_content">
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="E-Mail" id="email" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Confirm E-Mail" id="emailconf" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Desired Username" id="username" maxlength="20">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Password" id="pw" maxlength="64">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Confirm Password" id="pwconf" maxlength="64">
</div>
<div class="signup_tc">
<p>
<input type="checkbox" id="terms" value="terms_true" style="vertical-align:middle;">
I agree to the Terms and Conditions
<span class="signup_tc_required">*</span>
</p>
</div>
<input type="submit" id="submit" class="signup_submit" value="Create Account">
<div class="signup_alreadyMember">
Already a member? Login.
</div>
<div class="signup_error">
<span class="signup_error" id="fn_error_message"></span>
<span class="signup_error" id="ln_error_message"></span>
<span class="signup_error" id="email_error_message"></span>
<span class="signup_error" id="emailconf_error_message"></span>
<span class="signup_error" id="username_error_message"></span>
<span class="signup_error" id="pw_error_message"></span>
<span class="signup_error" id="pwconf_error_message"></span>
<span class="signup_error" id="tos_error_message"></span>
</div>
</div>
</form>
if you want to get your values using $_POST your inputs name attributes must be set
example add name="firstName"
<input type="text" class="signup_input_style_fn" name="firstName" id="firstName" placeholder="First Name" maxlength="20">
So now you can access it using
$firstName = $_POST['firstName'];
Change your "Id" to "name",and you will succeed.
You are missing name attribute from input , if you are not using ajax then you require name attribute
Use This
<form id="registration_form" action="http://valhq.com/register/" method="POST">
<div class="signup_form_content_names">
<div class="signup_form_input_fn">
<input type="text" class="signup_input_style_fn" id="firstName" name="firstName" placeholder="First Name" maxlength="20">
</div>
<div class="signup_form_input_ln">
<input type="text" class="signup_input_style_ln" id="lastName" name="lastName" placeholder="Last Name" maxlength="20">
</div>
</div>
<div class="signup_form_content">
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="E-Mail" id="email" name="email" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Confirm E-Mail" id="emailconf" name="emailconf" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Desired Username" id="username" name="username" maxlength="20">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Password" id="pw" name="pw" maxlength="64">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Confirm Password" id="pwconf" name="pwconf" maxlength="64">
</div>
<div class="signup_tc">
<p>
<input type="checkbox" id="terms" name="terms" value="terms_true" style="vertical-align:middle;">
I agree to the Terms and Conditions
<span class="signup_tc_required">*</span>
</p>
</div>
<input type="submit" id="submit" name="submit" class="signup_submit" value="Create Account">
<div class="signup_alreadyMember">
Already a member? Login.
</div>
<div class="signup_error">
<span class="signup_error" id="fn_error_message"></span>
<span class="signup_error" id="ln_error_message"></span>
<span class="signup_error" id="email_error_message"></span>
<span class="signup_error" id="emailconf_error_message"></span>
<span class="signup_error" id="username_error_message"></span>
<span class="signup_error" id="pw_error_message"></span>
<span class="signup_error" id="pwconf_error_message"></span>
<span class="signup_error" id="tos_error_message"></span>
</div>
</div>
</form>
Can you try echoing the variables in your php file to check if the variables are being set to the correct values from the form.
for example
echo "first name: $firstName";
echo "email: $email";
And I would also advise if you can try directly putting the actual php file in the action of your form. Just like below:
<form id="registration_form" action="<your php file here>" method="POST">

Submit button not working. No action is taken when i click on the create account button

This is the form on whic i'm working. i want it to send the data to 1.php but when i click on the create account button. please tell what is wrong with this code.
<div class="logmod__form">
<form accept-charset="utf-8" action="1.php" class="simform" method="post">
<div class="sminputs">
<div class="input full">
<label class="string optional" for="user-name">Email*</label>
<input class="string optional" maxlength="255" id="user-email" placeholder="Email" type="email" size="50" />
</div>
</div>
<div class="sminputs">
<div class="input string optional">
<label class="string optional" for="user-pw">Password *</label>
<input class="string optional" maxlength="255" id="user-pw" placeholder="Password" type="text" size="50" />
</div>
<div class="input string optional">
<label class="string optional" for="user-pw-repeat">Repeat password *</label>
<input class="string optional" maxlength="255" id="user-pw-repeat" placeholder="Repeat password" type="text" size="50" />
</div>
</div>
<div class="simform__actions">
<input class="sumbit" name="commit" type="sumbit" value="Create Account" />
<span class="simform__actions-sidetext">By creating an account you agree to our <a class="special" href="#" target="_blank" role="link">Terms & Privacy</a></span> </div>
</form>
</div>
Correct it in your button
type="submit"
You missed name Attribute in your fields without it nothing is submitted
<input class="string optional" maxlength="255" id="user-pw-repeat" placeholder="Repeat password" type="text" size="50" name="user-pw-repeat"/>

Add another code to webpage when the link is index.php?action=feed&type=member

Simply I want another code to be added to the webpage when the url is
index.php?action=feed&type=member
for example the code that is on the page when the url is index.php?action=feed is
<form method="post" name="contactform" class="form" id="form1" action="l.php">
<p class="name">
<input name="first_name" type="text" placeholder="Name" id="name" />
</p>
<p class="email">
<input name="email" type="text" id="email" placeholder="Email" />
</p>
<p class="text">
<textarea name="comments" placeholder="Message"></textarea>
</p>
<div class="submit">
<input type="submit" value="SEND" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
and the code I want to be added when the url is index.php?action=feed&type=member is
<form method="post" name="contactform" class="form" id="form1" action="l.php">
<p class="name">
<input name="first_name" type="text" placeholder="Name" id="name" />
</p>
<p class="email">
<input name="email" type="text" id="email" placeholder="Email" />
</p>
<p class="text">
<textarea name="comments" placeholder="Message"></textarea>
</p>
<p class="username">
<input name="user" type="text" id="user" placeholder="Username" />
</p>
<div class="submit">
<input type="submit" value="SEND" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
I know that it may be easy , but I am a beginner . so how can this be done in PHP ?
Sorry for my English .
Thanks in advance
If you want such output, you could put an if statement along the html form. Consider this example:
url: index.php?action=feed&type=member
<form method="post" name="contactform" class="form" id="form1" action="l.php">
<p class="name">
<input name="first_name" type="text" placeholder="Name" id="name"/>
</p>
<p class="email">
<input name="email" type="text" id="email" placeholder="Email"/>
</p>
<p class="text">
<textarea name="comments" placeholder="Message"></textarea>
</p>
<?php if(isset($_GET['type']) && $_GET['type'] == 'member'): ?>
<p class="username">
<input name="user" type="text" id="user" placeholder="Username"/>
</p>
<?php endif; ?>
<div class="submit">
<input type="submit" value="SEND" id="button-blue"/>
<div class="ease">
</div>
</div>
</form>
That particular markup should appear is those conditions are met.
if ($_GET["type"] == 'member') {
echo '<p class="username">
<input name="user" type="text" id="user" placeholder="Username" />
</p>';
}

Contact form with Bootstrap + Php not working

I am a beginner and I am trying to use this tutoriel http://untame.net/2013/05/how-to-build-a-modal-contact-form-in-twitter-bootstrap-with-php-ajax for creating my contact form. Email not sending ! Do you have an idea, why ? Thanks for your help !
After clicking on Send I have this on adresse web : http://viktorius.fr/?question=&email=&save=contact
Here the HTML code :
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_012_heart.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
</div>
<h5 id="Email" align="left" color="#000"<span style="color:black">For the answer, let us your email :</h5>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_290_skull.png"></span></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="Email">
</div>
<!-- Form itself -->
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary pull-right">Send</button><br />
Here the PHP code :
<?php
ini_set(“SMTP”,”smtp.viktorius.fr”);
ini_set(“smtp_port”,”25″);
$myemail = 'postmaster#viktorius.fr';
if (isset($_POST['question'])) {
$email = strip_tags($_POST['email']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
echo "<stong>Question:</strong> ".$question."<br>";
echo "<stong>Email:</strong> ".$email."<br>";
if (isset($_POST['name']))
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
Check the name of your inputs, php cant read your post data.
There is not a single form here...
the ajax expects to serialize
<form class="contact">...
$('form.contact').serialize(),
And you don't have a form
You should put all your inputs and button inside a form tag with class contact like this:
<form action="" class="contact">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_012_heart.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
</div>
<div style="margin-bottom: 25px;" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_290_skull.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" color="#000000"placeholder="For the answer, let us your email adress here :">
</div>
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary pull-right">Send</button><br>
</div>
</form>

How can I get the drop down menu to show? User Registration Form

I'm working through some legacy code from a previous developer and I'm very new to php. Here is my challenge, the registration form works as is.
The problem is the drop down menu that allows a user to self select their usertype does not appear on the form/page. I need it to.
Currently this bit of code stores all new users in the db as user1.
How can I get the drop down to show? And alter it from auto saving as user1?
index.html.php
<body id="page-login" onload="document.registerForm.name.focus();">
'. getMsg() .'
<div class="login-container">
<div class="logo_login"><img src="'. $mainframe->cfg->site_url .'/images/logo.gif"></div>
<div class="login-box">
<form method="post" action="" name="registerForm" id="registerForm" autocomplete="off">
<div class="login-form">
<h2>'. LANG::_('register') .'</h2>
<div class="input-box input-left"><label for="name">'. LANG::_('name') .':</label><br/>
<input type="text" class="txt" id="name" name="name" value="" class="required-entry input-text" style="width:130px;"/>
</div>
<div class="input-box input-left"><label for="link">'. LANG::_('Add your profile link') .':</label><br/>
<input type="text" class="txt" id="link" name="link" value="" class="required-entry input-text" style="width:130px;"/>
</div>
<div class="input-box input-left"><label for="username">'. LANG::_('user_name') .':</label><br/>
<input type="text" class="txt" id="username" name="username" value="" class="required-entry input-text" style="width:130px;"/>
</div>
<div class="input-box input-left"><label for="email">'. LANG::_('email_address') .':</label><br/>
<input type="text" class="txt" id="email" name="email" value="" class="required-entry input-text" style="width:130px;"/>
</div>
<div class="input-box input-left"><label for="password">'. LANG::_('password') .':</label><br />
<input type="password" class="txt" id="password" name="password" class="required-entry input-text" value="" style="width:130px;"/>
</div>
'. ($mainframe->cfg->allow_only_coach_or_player ? '<div class="input-box input-left"><label for="usertype">'. LANG::_('register_me_as') .':</label><br />
<select name="usertype" class="required-entry select">
<option value="">--'. LANG::_('choose_one') .'--</option>
<option value="Coach">'. LANG::_('contest_holder') .'</option>
<option value="Player">'. LANG::_('contest_participant') .'</option>
</select>
</div>'
: '<input name="usertype" value="user1" />') .'
<div class="input-box input-left"><label for="password2">'. LANG::_('r_password') .':</label><br />
<input type="password" class="txt" id="password2" name="password2" class="required-entry input-text" value="" style="width:130px;"/>
</div>`

Categories