PHP Mustache - multiple partials - php
I found this fiddle that shows how to include multiple partials in a Mustache template: http://jsfiddle.net/YW5zF/3/
I'm trying to convert this to PHP Mustache and having some difficulty. Can anyone help out here?
Essentially, I'm trying to understand how to reuse the input template several times in one template.
Here's my main template (contact.mustache):
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
{{>input}}
</div>
<div class="col-md-6">
{{>input}}
</div>
</div>
<div class="row">
<div class="col-md-6">
{{>input}}
</div>
<div class="col-md-6">
{{>input}}
</div>
</div>
<div class="row">
<div class="col-md-12">
{{>textarea}}
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-success btn-send" value="Send message">
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
</div>
</div>
</form>
Here's my input partial (input.mustache):
{{#input}}
<div class="{{div_class}}">
<label class="{{label_class}}" for="{{id}}">{{text}}</label>
<input type="{{type}}" id="{{id}}" name="{{name}}" class="{{input_class}}" placeholder="{{placeholder}}" {{required}} data-error="{{data-error}}">
<div class="{{line_class}}"></div>
</div>
{{/input}}
Here's my textarea template (textarea.mustache)
{{#textarea}}
<div class="{{div_class}}">
<label class="{{label_class}}" for="{{id}}">{{text}}</label>
<textarea id="{{id}}" name="{{name}}" class="{{input_class}}" placeholder="{{placeholder}}" rows="{{rows}}" {{required}} data-error="{{data-error}}"></textarea>
<div class="{{line_class}}"></div>
</div>
{{/textarea}}
Here's my PHP code to try to render it:
<?php
require_once __DIR__ . '/vendor/autoload.php';
$m = new Mustache_Engine;
$data = array(
0 =>array(
"div_class"=>"form-group",
"id"=>"form_name",
"type"=>"text",
"name"=>"name",
"placeholder"=> "Please enter your firstname *",
"required"=>"required='required'"
"data-error"=>"Firstname is required.",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Firstname *",
"line_class"=>"line-ripple",
),
1=> array(
"div_class"=>"form-group",
"id"=>"form_lastname",
"type"=>"text",
"name"=>"surname",
"placeholder"=> "Please enter your lastname *",
"required"=>"required='required'"
"data-error"=>"Lastname is required.",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Lastname *",
"line_class"=>"line-ripple",
),
2 =>array(
"div_class"=>"form-group",
"id"=>"form_email",
"type"=>"email",
"name"=>"email",
"placeholder"=> "Please enter your email *",
"required"=>"required='required'"
"data-error"=>"Valid email is required.",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Email *",
"line_class"=>"line-ripple",
),
3 =>array(
"div_class"=>"form-group",
"id"=>"form_phone",
"type"=>"tel",
"name"=>"phone",
"placeholder"=> "Please enter your phone",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Phone",
"line_class"=>"line-ripple",
),
4 =>array(
"div_class"=>"form-group",
"id"=>"form_message",
"name"=>"message",
"placeholder"=> "Message for me *",
"required"=>"required='required'"
"data-error"=>"Please,leave us a message.",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"rows"=>4,
"text"=>"Message *",
"line_class"=>"line-ripple",
)
);
// main templates in the /views folder, partials in the /views/partials folder
$m = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views'),
'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views/partials'),
));
// loads template from `views/contact.mustache` and renders it.
echo $m->render("contact", $data);
Current results of this script is:
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="floating-label" for="form_name">Firstname *</label>
<input type="text" id="form_name" name="name" class="form-control" placeholder="Please enter your firstname *" required='required' data-error="Firstname is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_lastname">Lastname *</label>
<input type="text" id="form_lastname" name="surname" class="form-control" placeholder="Please enter your lastname *" required='required' data-error="Lastname is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_email">Email *</label>
<input type="email" id="form_email" name="email" class="form-control" placeholder="Please enter your email *" required='required' data-error="Valid email is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_phone">Phone</label>
<input type="tel" id="form_phone" name="phone" class="form-control" placeholder="Please enter your phone" data-error="">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_message">Message *</label>
<input type="" id="form_message" name="message" class="form-control" placeholder="Message for me *" required='required' data-error="Please,leave us a message.">
<div class="line-ripple"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="floating-label" for="form_name">Firstname *</label>
<input type="text" id="form_name" name="name" class="form-control" placeholder="Please enter your firstname *" required='required' data-error="Firstname is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_lastname">Lastname *</label>
<input type="text" id="form_lastname" name="surname" class="form-control" placeholder="Please enter your lastname *" required='required' data-error="Lastname is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_email">Email *</label>
<input type="email" id="form_email" name="email" class="form-control" placeholder="Please enter your email *" required='required' data-error="Valid email is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_phone">Phone</label>
<input type="tel" id="form_phone" name="phone" class="form-control" placeholder="Please enter your phone" data-error="">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_message">Message *</label>
<input type="" id="form_message" name="message" class="form-control" placeholder="Message for me *" required='required' data-error="Please,leave us a message.">
<div class="line-ripple"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="floating-label" for="form_name">Firstname *</label>
<input type="text" id="form_name" name="name" class="form-control" placeholder="Please enter your firstname *" required='required' data-error="Firstname is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_lastname">Lastname *</label>
<input type="text" id="form_lastname" name="surname" class="form-control" placeholder="Please enter your lastname *" required='required' data-error="Lastname is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_email">Email *</label>
<input type="email" id="form_email" name="email" class="form-control" placeholder="Please enter your email *" required='required' data-error="Valid email is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_phone">Phone</label>
<input type="tel" id="form_phone" name="phone" class="form-control" placeholder="Please enter your phone" data-error="">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_message">Message *</label>
<input type="" id="form_message" name="message" class="form-control" placeholder="Message for me *" required='required' data-error="Please,leave us a message.">
<div class="line-ripple"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="floating-label" for="form_name">Firstname *</label>
<input type="text" id="form_name" name="name" class="form-control" placeholder="Please enter your firstname *" required='required' data-error="Firstname is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_lastname">Lastname *</label>
<input type="text" id="form_lastname" name="surname" class="form-control" placeholder="Please enter your lastname *" required='required' data-error="Lastname is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_email">Email *</label>
<input type="email" id="form_email" name="email" class="form-control" placeholder="Please enter your email *" required='required' data-error="Valid email is required.">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_phone">Phone</label>
<input type="tel" id="form_phone" name="phone" class="form-control" placeholder="Please enter your phone" data-error="">
<div class="line-ripple"></div>
</div>
<div class="form-group">
<label class="floating-label" for="form_message">Message *</label>
<input type="" id="form_message" name="message" class="form-control" placeholder="Message for me *" required='required' data-error="Please,leave us a message.">
<div class="line-ripple"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-success btn-send" value="Send message">
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
</div>
</div>
</form>
Why isn't it doing it correctly?
EDIT Finally got it working, changes are listed below...
Here's contact.mustache
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="controls">
{{>input}}
{{>textarea}}
<div class="col-md-12">
<input type="submit" class="btn btn-success btn-send" value="Send message">
</div>
<div class="row">
<div class="col-md-12">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
</div>
</div>
</form>
Here's input.mustache
{{#input}}
<div class="row">
<div class="col-md-6">
<div class="{{div_class}}">
<label class="{{label_class}}" for="{{id}}">{{text}}</label>
<input type="{{type}}" id="{{id}}" name="{{name}}" class="{{input_class}}" placeholder="{{placeholder}}" {{required}} data-error="{{data-error}}">
<div class="{{line_class}}"></div>
</div>
</div>
</div>
{{/input}}
Here's textarea.mustache
{{#textarea}}
<div class="row">
<div class="col-md-12">
<div class="{{div_class}}">
<label class="{{label_class}}" for="{{id}}">{{text}}</label>
<textarea id="{{id}}" name="{{name}}" class="{{input_class}}" placeholder="{{placeholder}}" rows="{{rows}}" {{required}} data-error="{{data-error}}"></textarea>
<div class="{{line_class}}"></div>
</div>
</div>
</div>
{{/textarea}}
Here's the data array (code stays same):
$data = array(
"input"=>array(
0 =>array(
"div_class"=>"form-group",
"id"=>"form_name",
"type"=>"text",
"name"=>"name",
"placeholder"=> "Please enter your firstname *",
"required"=>"required='required'",
"data-error"=>"Firstname is required.",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Firstname *",
"line_class"=>"line-ripple",
),
1=> array(
"div_class"=>"form-group",
"id"=>"form_lastname",
"type"=>"text",
"name"=>"surname",
"placeholder"=> "Please enter your lastname *",
"required"=>"required='required'",
"data-error"=>"Lastname is required.",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Lastname *",
"line_class"=>"line-ripple",
),
2 =>array(
"div_class"=>"form-group",
"id"=>"form_email",
"type"=>"email",
"name"=>"email",
"placeholder"=> "Please enter your email *",
"required"=>"required='required'",
"data-error"=>"Valid email is required.",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Email *",
"line_class"=>"line-ripple",
),
3 =>array(
"div_class"=>"form-group",
"id"=>"form_phone",
"type"=>"tel",
"name"=>"phone",
"placeholder"=> "Please enter your phone",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Phone",
"line_class"=>"line-ripple",
),
),
"textarea"=>array(
0 =>array(
"div_class"=>"form-group",
"id"=>"form_message",
"name"=>"message",
"placeholder"=> "Message for me *",
"required"=>"required='required'",
"data-error"=>"Please,leave us a message.",
"input_class"=>"form-control",
"label_class"=>"floating-label",
"text"=>"Message *",
"rows"=>4,
"line_class"=>"line-ripple",
),
)
);
Here's Output:
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="floating-label" for="form_name">Firstname *</label>
<input type="text" id="form_name" name="name" class="form-control" placeholder="Please enter your firstname *" required='required' data-error="Firstname is required.">
<div class="line-ripple"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="floating-label" for="form_lastname">Lastname *</label>
<input type="text" id="form_lastname" name="surname" class="form-control" placeholder="Please enter your lastname *" required='required' data-error="Lastname is required.">
<div class="line-ripple"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="floating-label" for="form_email">Email *</label>
<input type="email" id="form_email" name="email" class="form-control" placeholder="Please enter your email *" required='required' data-error="Valid email is required.">
<div class="line-ripple"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="floating-label" for="form_phone">Phone</label>
<input type="tel" id="form_phone" name="phone" class="form-control" placeholder="Please enter your phone" data-error="">
<div class="line-ripple"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="floating-label" for="form_message">Message *</label>
<textarea id="form_message" name="message" class="form-control" placeholder="Message for me *" rows="4" required='required' data-error="Please,leave us a message."></textarea>
<div class="line-ripple"></div>
</div>
</div>
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-success btn-send" value="Send message">
</div>
<div class="row">
<div class="col-md-12">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
</div>
</div>
</form>
What actually helped
The PHP render function seems to only have two parameters, unlike the Javascript one. So removing the third parameter and renaming {{>objPartial}} to {{>input}} so it matches the file should make it work with the PHP renderer.
Also, each time a partial is encountered in the main template, it will look at the data it's been given and create the code from the partial for each index of the array. The way your code is would work perfectly if each appearance of the partial only rendered for one element of the array.
At this point, you've very nearly got it working, just need to tweak a couple more things.
{{#input}}
<div class="col-md-6">
<div class="{{div_class}}">
<label class="{{label_class}}" for="{{id}}">{{text}}</label>
<input type="{{type}}" id="{{id}}" name="{{name}}" class="{{input_class}}" placeholder="{{placeholder}}" {{required}} data-error="{{data-error}}">
<div class="{{line_class}}"></div>
</div>
{{/input}}
And in the main template just have one reference to {{>input}}.
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
{{>input}}
</div>
<div class="row">
<div class="col-md-12">
{{>textarea}}
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-success btn-send" value="Send message">
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
</div>
</div>
</form>
There is a way to retain the format of one row div per two elements, but with bootstrap columns it's not necessary unless you're doing some sort of special formatting.
Old answer (retained in case it is useful for someone else)
There's a slight tweak here that I believe will make this work. Rather than calling the partial for each piece of content, call it once for the whole array of content. Your $data array would need to be slightly different, so here's what I'm seeing:
$data = array(
"input"=>array(
array(
"div_class"=>"text-field", "id"=>"firstName",
"input_class"=>"text-field__input", "label_class"=>"floating-label",
"line_class"=>"line-ripple", "text"=>"Curly"
)
),
array(
"div_class"=>"text-field", "id"=>"lastName",
"input_class"=>"text-field__input",
"label_class"=>"floating-label",
"line_class"=>"line-ripple", "text"=>"Athos"
)
)
);
And your partial would change slightly to include the .col-md-6:
{{#input}}
<div class="col-md-6">
<div class="{{div_class}}">
<input type="text" id="{{id}}" class="{{input_class}}">
<label class="{{label_class}}" for="{{id}}">{{text}}</label>
<div class="{{line_class}}"></div>
</div>
</div>
{{/input}}
Then you can replace
<div class="row">
<div class="col-md-6">
{{#firstname}}
{{>objPartial}}
{{/firstname}}
</div>
<div class="col-md-6">
{{#lastname}}
{{>objPartial}}
{{/lastname}}
</div>
</div>
with
<div class="row">
{{>objPartial}}
</div>
Related
Form in html not getting redirected to PHP file
I am creating a simple HTML website using bootstrap and CSS and am using PHP for form handling. I am using the POST method to submit the values of the form to a PHP file where I am trying to receive the values and printing them. However, when I press the submit button on the form, the HTML page is not getting redirected to the PHP file that is in the action element of the form. It just gets stuck on the HTML page. Please take a look at the below code and help me figure out why the values of the form are not getting submitted into the PHP file. This is the code for the form in the HTML file: <div class="container"> <div class="row"> <div class="contact-form"> <form action="contact.php" method="post" id="contact-form" role="form"> <fieldset> <div class="col-sm-6"> <div class="form-group"> <input type="text" name="fullname" class="form-control" id="full-name" placeholder="Full Name*" data-error="Full name is required" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input type="email" name="email" class="form-control" id="email" placeholder="Email Address*" data-error="Email is required" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input type="text" name="phone" class="form-control" placeholder="Phone number" id="phone" data-error="Phone number is required" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input type="text" class="form-control" placeholder="Subject*" name="subject" id="subject" data-error="Subject is required" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-12"> <div class="form-group"> <textarea cols="40" rows="10" name="message" class="textarea form-control" placeholder="Your Message" id="message" data-error="Message is required" required></textarea> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-4"> <div class="form-group"> <button class="btn-send" type="submit" name="submit">Send</button> </div> </div> <div class="col-sm-12"> <div class='form-response'></div> </div> </fieldset> </form> </div> </div> </div> The contact.php file looks something like this: <?php if ( isset( $_POST['submit'] ) ) { $fullName = $_POST['fullname']; $email = $_POST['email']; echo 'Your name is ' . $fullName .' and your email ID is' . $email; } ?> I have been unable to figure out exactly what the problem is. Please take look at this code and help me figure this problem out. Thanks in advance.
It should work. Have you made sure that the contact.php file is in the same folder as this html page?
put php code in same file. use this html <div class="container"> <div class="row"> <div class="contact-form"> <form action="" method="post"> <fieldset> <div class="col-sm-6"> <div class="form-group"> <input type="text" name="fullname" class="form-control" id="full-name" placeholder="Full Name*" data-error="Full name is required" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input type="email" name="email" class="form-control" id="email" placeholder="Email Address*" data-error="Email is required" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input type="text" name="phone" class="form-control" placeholder="Phone number" id="phone" data-error="Phone number is required" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input type="text" class="form-control" placeholder="Subject*" name="subject" id="subject" data-error="Subject is required" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-12"> <div class="form-group"> <textarea cols="40" rows="10" name="message" class="textarea form-control" placeholder="Your Message" id="message" data-error="Message is required" required></textarea> <div class="help-block with-errors"></div> </div> </div> <div class="col-sm-4"> <div class="form-group"> <button class="btn-send" type="submit" name="submit">Send</button> </div> </div> <div class="col-sm-12"> <div class='form-response'></div> </div> </fieldset> </form> </div> </div> </div>
Your code is perfectly working. Make sure your folders are in right place (eg : in wamp your folders must be inside www folder). And make sure your server is running.
Bootstrap Panel Body Left and Right
I want create panel-body bootstrap left and right here my code <div class="panel-body"> <p>1. Fill Full Name</p> <p> Example</p> <label for="name" class="col-sm-1 control-label">Full Name<span class="important">*</span></label> <div class="col-sm-3"> <input type="text" class="form-control" id="name" name="name" size="40" maxlength="50" disabled="disabled" value="Full Name" required> <div class="help-block with-errors"></div> </div> </div> <!-- Phone Ext --> <div class="panel-body"> <p>2. Fill Phone Extention</p> <p> Extention</p> <label for="name" class="col-sm-1 control-label">Phone Extention<span class="important">*</span></label> <div class="col-sm-3"> <input type="text" class="form-control" id="name" name="name" size="40" maxlength="50" disabled="disabled" value="Phone Extention" required> <div class="help-block with-errors"></div> </div> </div> and number 3 I want it in Right side Thanks a lot for your help
You could split the column like this : <div class="panel-body"> <div class="col-md-6"> <p>1. Fill Full Name</p> <p> Example</p> <label for="name" class="col-sm-2 control-label">Full Name<span class="important">*</span></label> <div class="col-sm-6"> <input type="text" class="form-control" id="name" name="name" size="40" maxlength="50" disabled="disabled" value="Full Name" required> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-6"> <p>3. Title #3</p> <p> Content for #3</p> <label for="name" class="col-sm-2 control-label">Label #3<span class="important">*</span></label> <div class="col-sm-6"> <input type="text" class="form-control" id="name" name="name" size="40" maxlength="50" disabled="disabled" value="Label #3" required> <div class="help-block with-errors"></div> </div> </div> </div> <!-- Phone Ext --> <div class="panel-body"> <p>2. Fill Phone Extention</p> <p> Extention</p> <label for="name" class="col-sm-1 control-label">Phone Extention<span class="important">*</span></label> <div class="col-sm-3"> <input type="text" class="form-control" id="name" name="name" size="40" maxlength="50" disabled="disabled" value="Phone Extention" required> <div class="help-block with-errors"></div> </div> </div>
how can i extract information from two forms in a html page then send it to my email (using php)
i have a static one page site, with two forms, that i want to extract the information of the fields of that forms then send it to my email this is the code of the two forms: my exact question is how can i creat a php page that can help me to handle the two forms and receive the info in my email <!-- Reservation Section --> <section id="reservation"> <div class="container"> <div class="row"> <div class="col-lg-12 text-center"> <h2 class="section-heading">Reserve Your Tour</h2> <h3 class="section-subheading ">Explore in Our <a class="page-scroll" href="#portfolio">Tours Secetion</a>, Make Your Mind, Make Your Reservation.</h3> </div> </div> <div class="row"> <div class="col-lg-12"> <form name="sentMessage" id="contactForm" novalidate> <div class="row"> <div class="col-md-6"> <div class="form-group"> <input type="text" class="form-control" placeholder="Your Name *" id="name2" required data-validation-required-message="Please enter your name."> <p class="help-block text-danger"></p> </div> <div class="form-group"> <input type="email" class="form-control" placeholder="Your Email *" id="email2" required data-validation-required-message="Please enter your email address."> <p class="help-block text-danger"></p> </div> <div class="form-group"> <input type="tel" class="form-control" placeholder="Your Phone *" id="phone2" required data-validation-required-message="Please enter your phone number."> <p class="help-block text-danger"></p> </div> <div class="form-group"> <input type="tel" class="form-control" placeholder="Your Country *" id="country" required data-validation-required-message="Please enter your country ."> <p class="help-block text-danger"></p> </div> <div class="form-group"> <input type="tel" class="form-control" placeholder="Number Of People *" id="number" required data-validation-required-message="Please enter The number of people your comming with."> <p class="help-block text-danger"></p> </div> </div> <!-- second half !!--> <div class="col-md-6"> <div class="form-group"> <input type="tel" class="form-control" placeholder="Date of arrival *(MM/DD/YYY)" id="dateofarrival" required data-validation-required-message="Please enter your Arrival Date."> <p class="help-block text-danger"></p> </div> <div class="form-group"> <input type="tel" class="form-control" placeholder="Date of departure * *(MM/DD/YYY)" id="dateofdeparture" required data-validation-required-message="Please enter your Date of departure *."> <p class="help-block text-danger"></p> </div> <div class="checkbox checkbox-inline"> <label><input type="checkbox" value="ToursFatima4Days" required data-validation-required-message="Please chose one tour at least">-Tours Fatima 4 Days</label> <label><input type="checkbox" value="ToursAicha5Days">-Tours Aicha 5 Days </label> <label><input type="checkbox" value="ToursAssmae9Days">-Tours Assmae 9 Days</label> <label><input type="checkbox" value="ToursZaina5Days">-Tours Zaina 5 Days</label> <label><input type="checkbox" value="AdventuresSafaris">-Adventures Safaris</label> </div> <br><br> <div class="form-group"> <textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea> <p class="help-block text-danger"></p> </div> </div> <div class="clearfix"></div> <div class="col-lg-12 text-center"> <div id="success"></div> <button type="submit" class="btn btn-xl">Submit Reservation</button> </div> </div> </form> </div> </div> </div> </section> <!-- end Reservation seccession --> <!-- Contact Section --> <section id="contact"> <div class="container"> <div class="row"> <div class="col-lg-12 text-center"> <h2 class="section-heading">Contact Us</h2> <h3 class="section-subheading text-muted">Let Us Know About Anything Going on Your Mind.</h3> </div> </div> <div class="row"> <div class="col-lg-12"> <form name="sentMessage" id="contactForm" method="post" action="mail/contact_me.php" <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> novalidate> <div class="row"> <div class="col-md-6"> <div class="form-group"> <input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name."> <p class="help-block text-danger"></p> </div> <div class="form-group"> <input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address."> <p class="help-block text-danger"></p> </div> <div class="form-group"> <input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number."> <p class="help-block text-danger"></p> </div> </div> <div class="col-md-6"> <div class="form-group"> <textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea> <p class="help-block text-danger"></p> </div> </div> <div class="clearfix"></div> <div class="col-lg-12 text-center"> <div id="success"></div> <button type="submit" class="btn btn-xl">Send Message</button> </div> </div> </form> </div> </div> </div> </section>
You're looking for PHP's mail function. There's also mail scripts that you can use. Check these out: http://www.inmotionhosting.com/support/edu/website-design/using-php-and-mysql/how-to-create-a-custom-php-contact-form http://www.inmotionhosting.com/support/email/send-email-from-a-page/using-phpmailer-to-send-mail-through-php
How to group HTML from with multiple fields with same name
I work on from to add more than one device when user click on add more But How can I group multiple fields with same name as array for every device from this form, my server side language is PHP. <form> <div class="row"> <div class="col-md-12"> <div class="widget stacked"> <div class="widget-header"> <i class="icon-hdd"></i> <h3>Remove Devices</h3> <a class="btn label label-success add_new_device">Add more</a> </div> <div class="widget-content"> <div class="form-group"> <label for="device_name">Device Name</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[device_name][]" type="text"> </div> <div class="form-group"> <label for="device_description">Device Description</label> <input class="form-control" data-validation="length" data-validation-length="max255" data-validation-optional="true" name="device[device_description][]" type="text"> </div> <div class="form-group"> <label for="device_url">Device Url</label> <input class="form-control" data-validation="url" data-validation-optional="true" data-validation-help="Ex: http://000.000.000.000/index.cgi" name="device[device_url][]" type="url"> </div> <div class="form-group"> <label for="device_ip4">IP4</label> <input class="form-control" data-validation="length" data-validation-length="max15" data-validation-optional="true" data-validation-help="Ex: 000.000.000.000" name="device[device_ip4][]" type="text"> </div> <div class="form-group"> <label for="device_ip6">IP6</label> <input class="form-control" data-validation="length" data-validation-length="max45" data-validation-help="Ex: 0000:0000:0000:0000:0000:0000" name="device[][device_ip6]" type="text"> </div> <div class="form-group"> <label for="device_username">Device Username</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[][device_username]" type="text"> </div> <div class="form-group"> <label for="device_password">Device Password</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[][device_password]" type="text"> </div> </div> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="widget stacked"> <div class="widget-header"> <i class="icon-hdd"></i> <h3>Remove Devices</h3> <a class="btn label label-success add_new_device">Add more</a> </div> <div class="widget-content"> <div class="form-group"> <label for="device_name">Device Name</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[device_name][]" type="text"> </div> <div class="form-group"> <label for="device_description">Device Description</label> <input class="form-control" data-validation="length" data-validation-length="max255" data-validation-optional="true" name="device[device_description][]" type="text"> </div> <div class="form-group"> <label for="device_url">Device Url</label> <input class="form-control" data-validation="url" data-validation-optional="true" data-validation-help="Ex: http://000.000.000.000/index.cgi" name="device[device_url][]" type="url"> </div> <div class="form-group"> <label for="device_ip4">IP4</label> <input class="form-control" data-validation="length" data-validation-length="max15" data-validation-optional="true" data-validation-help="Ex: 000.000.000.000" name="device[device_ip4][]" type="text"> </div> <div class="form-group"> <label for="device_ip6">IP6</label> <input class="form-control" data-validation="length" data-validation-length="max45" data-validation-help="Ex: 0000:0000:0000:0000:0000:0000" name="device[][device_ip6]" type="text"> </div> <div class="form-group"> <label for="device_username">Device Username</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[][device_username]" type="text"> </div> <div class="form-group"> <label for="device_password">Device Password</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[][device_password]" type="text"> </div> </div> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="widget stacked"> <div class="widget-header"> <i class="icon-hdd"></i> <h3>Remove Devices</h3> <a class="btn label label-success add_new_device">Add more</a> </div> <div class="widget-content"> <div class="form-group"> <label for="device_name">Device Name</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[device_name][]" type="text"> </div> <div class="form-group"> <label for="device_description">Device Description</label> <input class="form-control" data-validation="length" data-validation-length="max255" data-validation-optional="true" name="device[device_description][]" type="text"> </div> <div class="form-group"> <label for="device_url">Device Url</label> <input class="form-control" data-validation="url" data-validation-optional="true" data-validation-help="Ex: http://000.000.000.000/index.cgi" name="device[device_url][]" type="url"> </div> <div class="form-group"> <label for="device_ip4">IP4</label> <input class="form-control" data-validation="length" data-validation-length="max15" data-validation-optional="true" data-validation-help="Ex: 000.000.000.000" name="device[device_ip4][]" type="text"> </div> <div class="form-group"> <label for="device_ip6">IP6</label> <input class="form-control" data-validation="length" data-validation-length="max45" data-validation-help="Ex: 0000:0000:0000:0000:0000:0000" name="device[][device_ip6]" type="text"> </div> <div class="form-group"> <label for="device_username">Device Username</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[][device_username]" type="text"> </div> <div class="form-group"> <label for="device_password">Device Password</label> <input class="form-control" data-validation="length" data-validation-length="max128" data-validation-optional="true" name="device[][device_password]" type="text"> </div> </div> </div> </div> </div> </form>
Name your fields like devices[0][description], devices[1][description] and so on. If every object has the exact same number of fields and every one is a new record - you can use devices[][description] and browser will fill indexes for you, but this can lead to bugs in the future, if you decide to use same form for editing records. Also see How to get form input array into PHP array
The requested URL /chat//layercake/form_validation was not found on this server
In Codeigniter I am trying to call a function from form action and I get the following error: requested URL /chat//layercake/form_validation was not found on this server. <form class="form-horizontal" id="contact" data-toggle="validator" enctype="multipart/form-data" role="form" method="post" action="<?php echo base_url().'/layercake/form_validation'; ?>"> <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="" required> <div class="help-block with-errors"></div> </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="" required> <div class="help-block with-errors"></div> </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" id="message" rows="4" name="message" required></textarea> <div class="help-block with-errors"></div> </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-sm-10 col-sm-offset-2 alert"> </div> </div> </form> Please help.
Change your action url base_url().'/layercake/form_validation'; to base_url().'layercake/form_validation'; Please look at your error. There are two // after chat.
Your action URL is wrong. Change action="<?php echo base_url().'/layercake/form_validation'; ?>" this as following in form tag action="<?php echo site_url('layercake/form_validation'); ?>"