im trying to create a templated system with CI. So far everything is working flawlessly and im testing out form validation but its not working at all. As you can see from the code below there are both html5 required statements as well as the codeigniter rules. Neither of which are working after I hit the submit button. So i'm not sure whats going wrong. Something stupid im sure.
public function show_form(){
$form_data = '<div class="row">
<div class="col-md-12">
<div class="card-box">
<h4 class="m-t-0 header-title"><b>Basic Form Wizard</b></h4>
<form id="basic-form" action="#">
<div>
<h3>Account</h3>
<section>
<div class="form-group clearfix">
<label class="col-lg-2 control-label " for="username">User name *</label>
<div class="col-lg-10">
<input class="form-control" id="username" name="username" type="text">
</div>
</div>
<div class="form-group clearfix">
<label class="col-lg-2 control-label " for="password"> Password *</label>
<div class="col-lg-10">
<input id="password" name="password" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="col-lg-2 control-label " for="confirm">Confirm Password *</label>
<div class="col-lg-10">
<input id="confirm" name="confirm" type="text" class="required form-control">
</div>
</div>
</section>
<input type="submit" value="Submit" />
</div>
</form>
</div>
</div>
</div>';
$this->CI->form_validation->set_rules('username', 'Username', 'required');
if ( $this->CI->form_validation->run() == FALSE ):
echo "<pre>Before Validation</pre>";
echo validation_errors();
echo "<pre>After Validation</pre>";
echo $form_data;
else:
echo "We did it";
endif;
}
Thanks in advance for any guidance.
Related
Hi I am new to php and am not quite sure how to do this I am attempting to build a contact form that sends an email currently the HTML I Have for the form is:
<section class="mbr-section form1 cid-qL6aon4aVW" id="form1-11">
<div class="container">
<div class="row justify-content-center">
<div class="title col-12 col-lg-8">
<h2 class="mbr-section-title align-center pb-3 mbr-fonts-style display-2">
MAINTENANCE FORM
</h2>
<h3 class="mbr-section-subtitle align-center mbr-light pb-3 mbr-fonts-style display-5">
Request Maintenance for your unit.</h3>
</div>
</div>
</div>
<div class="container">
<div class="row justify-content-center">
<div class="media-container-column col-lg-8" data-form-type="formoid">
<form class="mbr-form" action="feedback.php" method="post">
<div class="row row-sm-offset">
<div class="col-md-4 multi-horizontal" data-for="name">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="name-form1-11">Full Name</label>
<input type="text" class="form-control" name="name" data-form-field="Name" required="" placeholder="Full Name" id="name-form1-11">
</div>
</div>
<div class="col-md-4 multi-horizontal" data-for="email">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="email-form1-11">Email Address</label>
<input type="email" class="form-control" name="email" data-form-field="Email" required="" placeholder="Email" id="email-form1-11">
</div>
</div>
<div class="col-md-4 multi-horizontal" data-for="phone">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="phone-form1-11">Phone Number</label>
<input type="tel" class="form-control" name="phone" data-form-field="Phone" placeholder="Phone #" id="phone-form1-11">
</div>
</div>
</div>
<div class="form-group" data-for="message">
<label class="form-control-label mbr-fonts-style display-7" for="message-form1-11">Request</label>
<textarea type="text" class="form-control" name="message" rows="7" data-form-field="Message" placeholder="Request" id="message-form1-11"></textarea>
</div>
<span class="input-group-btn">
<button href="" type="submit" class="btn btn-primary btn-form display-4">SEND FORM</button>
</span>
</form>
</div>
</div>
</div>
And the PHP I have is :
<?php
if (isset($_POST['submit'])){
$to="email#email.com";
$subject="Shovers.net Maintenance form submission";
$mail_from="from: ".$_POST['email']." \n";
$mail_from .="Content-Type: text/html; charset=utf-8 \n";
$message="<font size=\"2\" face=\"Verdana\"> Here is the message:<br />
".$_POST['comments']."<br />
".$_POST['name']."<br />
".$_POST['email']."</font>";
mail($mail_from,$to,$subject,$comments);
echo "Thanks!";
$TARGET = "/";
header("Location: $TARGET");
exit();
}else{
}
?>
I can't seem to get this to send to my email and I am not sure why on form submit it currently just goes to the feedback.php page which is blank as it is just the PHP script. Does this need to be running on the actual server for it to work or will it work with xampp and apache/mysql running? If not what do I need to do to get this working?
In addition I am also trying to get it to just reload/stay on that same page but pop up a verification message what am I doing wrong for that?
Any help appreciated!
Thanks!
I can send data to database but using tag. I want to use tag so that the validation in my page will show like "please enter a valid email-address", "password do not match" and many more.
The problem is when I use tag it shows no validation but the data send to db.
But if use tag it shows the validation, but the data is not entering into db.
Here is the view code:
<div class="form-horizontal" id="block-validate">
<?php echo form_open(base_url("index.php/main/editClass"));?>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Course Code-Section
</b></label>
<div class="col-lg-4">
<input class="form-control" name="ccs" type="text" value="<?php echo $Course_Code_Section;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Course Description
</b></label>
<div class="col-lg-4">
<input class="form-control" name="des" type="text" value="<?php echo $Description;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
School Year-Semester
</b></label>
<div class="col-lg-4">
<input class="form-control" name="sys" type="text" value="<?php echo $School_Year_Semester;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Room
</b></label>
<div class="col-lg-4">
<input class="form-control" name="rm" type="text" value="<?php echo $Room;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Day-Time
</b></label>
<div class="col-lg-4">
<input class="form-control" name="dt" type="text" value="<?php echo $Day_Time;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Student
</b></label>
<div class="col-lg-4">
<input class="form-control" name="stu" type="text" value="<?php echo $Student;?>">
</div>
</div>
<div class="form-actions">
<input type="hidden" name="id" value="<?php echo $CID;?>">
<label class="control-label col-lg-2"></label>
<button type="submit" class="btn btn-primary btn-grad btn-rect">Submit</button>
Cancel
</div>
<?php echo form_close();?>
</div>
Here is the code that I am changing:
<div class="form-horizontal" id="block-validate">
And I changed it to:
<form class="form-horizontal" id="block-validate">
When I use the form tag, the url shows this:
http://localhost/ams/index.php/main/showEditClassView?ccs=CPE+506-CPE42FA1&des=Software+Engineering&sys=SY+2016-2017+2nd+Sem&rm=A-225&dt=Saturday-07%3A30+AM-12%3A30+PM&stu=Ronnel+Gonzales&id=1
What if you modify:
<div class="form-horizontal" id="block-validate">
<?php echo form_open(base_url("index.php/main/editClass"));?>
to:
<div class="form-horizontal">
<?php echo form_open(base_url("index.php/main/editClass"), 'id="block-validate"');?>
So that Codeigniter opens the form tag for you, but we use id="block-validate" so your validation can run?
Use method="POST" if you do not want to appear the values in the url.Hope this will sort your problem.
<form class="form-horizontal" id="block-validate" method="POST">
When i post a Message from my web page it returns a ? in the browser such as this,
I believe both the HTML and the php to be correct
The html......
`enter code here`
<form class="form-horizontal">
<fieldset>
<div class="form-group is-empty">
<label for="Name" class="col-md-2 control- label">Name</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group is-empty">
<label for="Email" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group is-empty">
<label for="Message" class="col-md-2 control-label">Message</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Message" placeholder="Message">
</div>
</div>
<div class="form-group">
<form action="sendcontact.php" method="post">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</section>
enter code here
you have declare form method and its action in form tag. Something like as follows
<form action="actionPage.php" method="POST"> //you can send data in get method or post method
Hope this will work for you...
action="yourLoctionUrl" tell the form where to submit data.
if you will do it empty then it will show ?yourinput fields&other inputs
<form action="sendcontact.php" method="post" class="form-horizontal">
<fieldset>
<div class="form-group is-empty">
<label for="Name" class="col-md-2 control- label">Name</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group is-empty">
<label for="Email" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group is-empty">
<label for="Message" class="col-md-2 control-label">Message</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Message" placeholder="Message">
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
You have used form tag twice in your coding. put your action and post in starting form tag as i did.
You didn't close the second form tag. Go for this:
<form action="sendcontact.php" method="post">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</form>
I want to add a contact form on my page but I've never worked with PHP before. I need help, please?
I'm working with the form below:
<a name="Contact"></a>
<div class="contact">
<div class="container">
<div class="row">
<div class="col-lg-8">
<h1 class="page-header text-center">Get in touch!</h1>
<form class="form-horizontal" role="form" method="post" action="index.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
</div>
<div class="form-group">
<label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</form>
</div>
For for some reason, it's not displaying properly. This is how it looks:
screenshot of contact form
I have a simple Login page where I show a error message on failed authentication. I have a div with some classes applied , and inside it I display the error message through a <label.../>.
Now when the page is loaded for the first time, there is obviously no error message and thus there is an blank space left.
What I want is if there is no error message, the div should occupy no space or should be hidden and should only show if there is any text(error message) inside the div.
Here is my HTML :
<form id="login-form" action="authenticate.php" method="post" role="form" style="display: block;">
<div class="form-group">
<input type="text" name="login_email" id="login_email" tabindex="1" class="form-control" placeholder="Email" value="">
</div>
<div class="form-group">
<input type="password" name="login_password" id="login_password" tabindex="2" class="form-control" placeholder="Password">
</div>
<div class="form-group text-center">
<label style="color:red"><?php if(isset($error)) echo $error; ?></label>
</div>
<div class="form-group text-center">
<input type="checkbox" tabindex="3" class="" name="remember" id="remember">
<label for="remember"> Remember Me</label>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="login-submit" id="login-submit" tabindex="4" class="form-control btn btn-login" value="Log In">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<div class="text-center">
Forgot Password?
</div>
</div>
</div>
</div>
</form>
PHP code :
<?php
if(isset($_GET['login_error'])){
if($_GET['login_error']== 'true'){
$error = "Email and/or Password was incorrect! Please try again!";
}
}
?>
Change it so that it calls out all the HTML in the php function. Like this
<?php
if(isset($_GET['login_error'])){
if($_GET['login_error']== 'true'){
$error = '<div class="form-group text-center">';
$error .= '<label style="color:red">Email and/or Password was incorrect! Please try again!</label>';
$error .= '</div>';
}
}
?>
<form id="login-form" action="authenticate.php" method="post" role="form" style="display: block;">
<div class="form-group">
<input type="text" name="login_email" id="login_email" tabindex="1" class="form-control" placeholder="Email" value="">
</div>
<div class="form-group">
<input type="password" name="login_password" id="login_password" tabindex="2" class="form-control" placeholder="Password">
</div>
<!-- ERROR MESSAGE IS HERE -->
<?php if(isset($error)) echo $error; ?>
<div class="form-group text-center">
<input type="checkbox" tabindex="3" class="" name="remember" id="remember">
<label for="remember"> Remember Me</label>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="login-submit" id="login-submit" tabindex="4" class="form-control btn btn-login" value="Log In">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<div class="text-center">
Forgot Password?
</div>
</div>
</div>
</div>
</form>
Change the content of the if statement to include the entire element, like so:
<?php if(isset($error)) { ?>
<div class="form-group text-center">
<label style="color:red"><?php echo $error; ?></label>
</div>
<?php } ?>