• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to make if else have data message div

#1
[eluser]razerone[/eluser]
Hi.

I have just about finished with my contact form but when message is sent I would like it to show up above my send buttons in new <div class="alert alert-success"></div>

At the moment it get directed to a confirmation page. Any ideas how to get that success message div showing up above submit buttons

Code:
public function confirmation() {
$this->load->library('form_validation');
$this->form_validation->set_rules('fullname', 'Full Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('header');
$this->load->view('contactus');
$this->load->view('footer');
} else {
$this->load->view('header');
$this->load->view('confirmation');
$this->load->view('footer');
}
}


Code:
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div id="contactus">
<h1>Contact Us</h1>
<hr>
&lt;?php
$this->load->helper('form');
echo validation_errors();
$data = array(
"name" => "contact-form",
"id" => "contact-form",
"role" => "form"
);
echo form_open('contactus/confirmation', $data);
?&gt;
<div class="form-group">
&lt;?php
$data = array(
"name" => "fullname",
"id" => "fullname",
"class" => "form-control",
"value" => "",
"placeholder" => "Your Name"
);
echo form_input($data);
$data = array(
"name" => "email",
"id" => "email",
"class" => "form-control",
"value" => "",
"placeholder" => "Your Email"
);
echo form_input($data);
$data = array(
name" => "subject",
"id" => "subject",
"class" => "form-control",
"value" => "",
"placeholder" => "Your Subject"
);
echo form_input($data);
$data = array(
"name" => "message",
"id" => "message",
"class" => "form-control",
"rows" => "10",
"value" => "",
"placeholder" => "Please Enter Your Message"
);
echo form_textarea($data);

/// Need If Else Success Message <div class="alert alert-success">$messagesuccess</div>

$data = array(
"name" => "submit",
"id" => "sumbit",
"class" => "btn btn btn-primary",
"value" => "Send Message"
);
echo form_submit($data);
$data = array(
"name" => "reset",
"id" => "reset",
"class" => "btn btn btn-danger",
"style" => "margin-left: 2%;",
"value" => "Reset Your Details"
);
echo form_reset($data);
?&gt;
</div>
&lt;?php echo form_close();?&gt;
</div>
</div>
</div>

#2
[eluser]DuyK-DCT[/eluser]
Your code is too long to read, but i've read your problem and i will show you a suggest

In controller
Code:
public function your_controller()
{
  ... Your set rules here...
  $result = $this->form_validation->run();
  
    $this->load->view('your_view', array('result' => $result));
  
}

In your view

Code:
&lt;?php if($result){ ?&gt;
<div class="alert alert-success">Your message when success</div>
&lt;?php }else{ ?&gt;
<div class="alert alert-warning">Your message when failed</div>
&lt;?php } ?&gt;

#3
[eluser]razerone[/eluser]
[quote author="DuyK-DCT" date="1383851733"]Your code is too long to read, but i've read your problem and i will show you a suggest

In controller
Code:
public function your_controller()
{
  ... Your set rules here...
  $result = $this->form_validation->run();
  
    $this->load->view('your_view', array('result' => $result));
  
}

In your view

Code:
&lt;?php if($result){ ?&gt;
<div class="alert alert-success">Your message when success</div>
&lt;?php }else{ ?&gt;
<div class="alert alert-warning">Your message when failed</div>
&lt;?php } ?&gt;
[/quote]

Sorry thanks for help but had worked it out couple of days ago thanks.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.