Here is my form element
<form method="post" id="add_facility_form" class="blocks" action="<?php echo base_url(); ?>index.php/facility_management/add">
<div id="contact_wrapper">
<p>Name: </p>
<input type="text" class="inp-form" name="contact_name[]" />
<p>Department: </p>
<input type="text" class="inp-form" name="department_name[]" />
<p>Email: </p>
<input type="text" class="inp-form" name="contact_email[]" />
<p>Phone number: </p>
<input type="text" class="inp-form" name="contact_phone_number[]" />
<p>Fax number: </p>
<input type="text" class="inp-form" name="contact_fax_number[]" />
</div>
<img width="21" height="21" alt="" src="<?php echo base_url() ?>images/forms/icon_plus.gif" class="add_new_contact add_new" />
</form>
when I click on the image it clones the whole div.I want to post the data but the problem is that it posts only first div's information.How can I post the cloned element's data?
here is jquery function and php
$(".add_new_contact").click(function () {
$("#contact_wrapper").clone().attr('id','contact_wrapper'+new Date().getTime()).appendTo($(this).parent());
return false;
});
PHP
$contact_name = $this->input->post('contact_name');
$department = $this->input->post('department_name');
$contact_phone = $this->input->post('contact_phone_number');
$contact_fax = $this->input->post('contact_fax_number');
$contact_email = $this->input->post('contact_email');
$contact_count = count($contact_name);
<?php
$array=$_POST['contact_name'];
foreach($array as $name)
{
echo "Name is ".$name."<br>";
}
$array=$_POST['contact_email'];
foreach($array as $email)
{
echo "email is ".$email."<br>";
}
?>
Related
I am trying to execute this html form code, the php script is not executing properly. Can you point out the problems?
<form action="form.php" method="post">
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
php script
<?php
if (isset($_POST['submit']))
{
$k=0;
foreach($_POST['languages'] as $language) {
echo $language = htmlentities($language);
echo $title = $_POST['titles'][$k];
$k++;
}
}
?>
HTML
<form action="form.php" method="post">
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<input type="submit" name="submit" id="submit" value="Submit">
</form>
PHP
<?php
if (isset($_POST['submit']))
{
foreach($_POST['languages'] as $key => $language) {
echo $language = htmlentities($language);
echo " -- ";
echo $title = $_POST['titles'][$key];
echo "<br/>";
}
}
?>
I am using below code for a html form.(it has two forms) I am able to keep the textarea field after the first and second form submission. but issue I am facing here is the dropdown menu selection.
Code:
<html>
<body>
<div class="emcsaninfo-symcli-main">
<form id="form1" name="form1" action=" " method="post" >
<div class="input">Your Name</div>
<div class="response"><span><input class="textbox" id="myname" name="myname" type="text" value="<?php if(isset($_POST['myname'])) { echo htmlentities ($_POST['myname']); }?>" /></span> </div>
<div class="input">Your Place</div>
<div class="response"><span><input class="textbox" id="myplace" name="myplace" type="text" value="<?php if(isset($_POST['myplace'])) { echo htmlentities ($_POST['myplace']); }?>" /></span> </div>
<div class="input-quest">Graduation Status</div>
<div class="input-resp"><select id="graduation" name="graduation" OnChange="CMT();"><option class="dropdown-options">Graduate</option><option class="dropdown-options">Non Graduate</option></select></div>
<div class="submit">
<input id="first_submit" type="submit" name="first_submit" value="first_submit" />
</div>
</form>
<?php
if(!empty($_POST['myname']) && !empty($_POST['myplace']) || !empty($_POST['output_textarea'] ) )
{
$myname = $_POST['myname'];
$myplace = $_POST['myplace'];
$graduation = $_POST['graduation'];
?>
<form id="form2" name="form2" action=" " method="post" >
<textarea onclick="this.select()" name="output_textarea" id="output_textarea" cols="100" rows="25" readonly value="<?php if(isset($_POST['output_textarea'])) { echo htmlentities ($_POST['output_textarea']); }?>">
<?php
echo "My name is $myname and I am from $myplace, and I am $graduation";
?>
</textarea>
<input id="submit1" type="submit" name="name_field" value="submit1" />
<input id="submit2" type="submit" name="place_field" value="submit2" />
<input id="myname_hidden" name="myname" type="hidden" value="<?php if(isset($_POST['myname'])) { echo htmlentities ($_POST['myname']); }?>"/>
<input id="myplace_hidden" name="myplace" type="hidden" value="<?php if(isset($_POST['myplace'])) { echo htmlentities ($_POST['myplace']); }?>" />
<input id="graduation_hidden" name="graduation" type="hidden" value="<?php if(isset($_POST['graduation'])) { $graduation = $_POST['graduation']; }?>" />
</form>
<?php
function name()
{
echo $_POST["output_textarea"];
}
if(isset($_POST['name_field']))
{
name();
}
function place()
{
echo $_POST["output_textarea"];
}
if(isset($_POST['place_field']))
{
place();
}
}
?>
</div>
</html>
</body>
For example if I put name = John, place : UK and selecting graduation status as graduate, it will will give me first form output as in my output textarea
My name is John and I am from UK, and I am Graduate
I have two seperate submit button for second form, using that I am doing some other function with help of the output textarea
If I press any of the second button,I m able to keep entries my name and place area, but it not keeping the dropdown selection. so it will only display like after submitting submit1 or submit2
My name is John and I am from UK, and I am
Here,
How can I keep the the dropdown selection also with the output text area
Will I able to show only the output_textarea content after second form submission without keeping the first form data ?
PHP FIDDLE
You have an error in logic in the hidden input for the "graduate" element.
This is what you have at lines 53-55. Line 55 doesn't have an echo instead it has an $graduation = $_POST['graduation']; which won't help you:
<input id="myname_hidden" name="myname" type="hidden" value="<?php if(isset($_POST['myname'])) { echo htmlentities ($_POST['myname']); }?>"/>
<input id="myplace_hidden" name="myplace" type="hidden" value="<?php if(isset($_POST['myplace'])) { echo htmlentities ($_POST['myplace']); }?>" />
<input id="graduation_hidden" name="graduation" type="hidden" value="<?php if(isset($_POST['graduation'])) { $graduation = $_POST['graduation']; }?>" />
instead of that, this code should work:
<input id="myname_hidden" name="myname" type="hidden" value="<?php if(isset($_POST['myname'])) { echo htmlentities ($_POST['myname']); }?>"/>
<input id="myplace_hidden" name="myplace" type="hidden" value="<?php if(isset($_POST['myplace'])) { echo htmlentities ($_POST['myplace']); }?>" />
<input id="graduation_hidden" name="graduation" type="hidden" value="<?php if(isset($_POST['graduation'])) { echo htmlentities($_POST['graduation']); }?>" />
I want to check if either of my search fields are empty, and if they are i write out a failure message. For some reason the following code doesn't work when I try to submit empty values in both search fields, or leaving the q2 search field empty. It only writes out the failure message when I only insert a value into the first field. Hope you guys can help.
<div id="searchField">
<form name="searchField" action="" method="get">
<input type="search" name="q" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/>
<input type="search" name="q2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/>
<input type="hidden" id="v" name="v" value="2" />
<input type="hidden" id="b" name="b" value="" />
<button type="submit" id="loop" style="border:0px; background:transparent; vertical-align:middle; margin-left:-85px; margin-top:-3px;">
<img src="images/loop.png" width="75" height="75" alt="submit" />
</button>
</form>
</div>
<div id="theData">
<?
if(str_replace(" ", "",$_GET['q'])!="" && str_replace(" ","",$_GET['q2'])!=""){
$qContent = $_GET['q'];
$succes = mysql_query("SELECT*FROM film WHERE name='".$qContent."'");
include("searchMaster.php");
if(mysql_num_rows($succes)) {
while($o = mysql_fetch_array($succes)){
echo $o['name'];
if($o['trailer']){
echo '<div id="ytplayerWrap">';
echo '<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/'.$o['trailer'].'?http://amnestic.ueuo.com"
frameborder="0"/>';
echo '</div>';
}else {
echo '<span style="font-size:20px;">';
echo '<br /><br /> No trailer was found for <em>'.$_GET['q'].'</em> :(';
echo '</span>';
}
}
}else{
echo 'You did the fuckup :(';
}
}else{
echo 'You did the fuckup :(';
}
?>
The name and id of your input fields must be same
Like this
<input type="text" name="submitQuery" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/>
<input type="text" name="submitQuery2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/>
I have two text boxes and one button. I want when i will type any value in 1st textbox and click on a button the value which i'll type in 1st text box should be the value of 2nd text box. And i was using this code. Can some one help me on this?
<?php
if(isset($_POST['sum']))
{
$v1=$_POST['abc'];
if($v1=="vivek")
{
echo "welcome Mr.".$v1;
}
else
{
echo "Unauthorised User Mr. ".$v1;
}
}
?>
<html>
<body>
<form method="post" action="">
<p>Name:     
<input type="text" name="abc" value=""/>  
</br></br>
Passed Value: <input type="text" name="xyz" value="<?php echo $v1;?>"/>
</p>
<p>
<input type="submit" name="sum" value=" Submit "/>
</p>
</form>
</body>
</html>
try this one.
<form method="post" action="">
<p>Name:     
<input type="text" name="abc" value=""/>  
</br></br>
Passed Value: <input type="text" name="xyz" value="<?php if(isset($_POST['abc'])) { echo $_POST['abc']; } ?>"/>
</p>
<p>
<input type="submit" name="sum" value=" Submit "/>
</p>
</form>
Passed Value:
<input type="text" name="xyz" value="<?php
if(isset($_POST['abc']))
echo htmlentities($_POST['abc'],ENT_QUOTES);
?>"/>
This should do it :)
Try this code.
<script type="text/javascript">
function sub() {
document.getElementById('xyz').value = document.getElementById('abc').value;
}
</script>
<form>
<label>Amonut</label>
<input type="text" name="abc" onkeyup="sub();" id="abc" />
<br /><br />
<label>Discount</label>
<input type="text" name="xyz" id="xyz" />
<input type="submit" name="sum" value=" Submit "/>
</form>
<script type="text/javascript">
function sub() {
document.getElementById('xyz').value = document.getElementById('abc').value;
}
</script>
<form onsubmit="sub();">
<label>Amonut</label>
<input type="text" name="abc" id="abc" />
<br /><br />
<label>Discount</label>
<input type="text" name="xyz" id="xyz" />
<input type="submit" name="sum" value=" Submit "/>
</form>
I think you want this.
Try this code
$v1='';
if(isset($_POST['sum']))
{
if($v1=="vivek")
{
echo "welcome Mr.".$v1;
$v1=$_POST['abc'];
}
else
{
echo "Unauthorised User Mr. ".$v1;
}
}
When I submitted the form data, I received this error on Line 13 (array_push($order,$add_order);) of my PHP code: "Warning: Invalid argument supplied for foreach()..."
What's the best way to get this PHP code working?.
Here is the current email output (None of the data seems to be sending properly except for the Name & Phone number field):
Name: Alex
Phone: 5104545778
Item: Array
Quantity:
Add:
Message:
PHP:
<?php
if(isset($_POST['submit'])) {
$to = "test#mywebsite.com";
$subject = "New Order";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$order = array();
foreach($_POST['item'] as $item => $name) {
if ($_POST['quantity_'.$name] > 0) {
$add_order = array('pretty'=>$_POST['pretty-name_'.$name],'qty'=>$_POST['quantity_'.$name],'message'=>$_POST['message_'.$name]);
array_push($order,$add_order);
}
}
$body = "From: $name_field\nE-Mail: $email_field\n";
$body .= "Their Order:\n";
foreach ($order as $item){
$body .= "--".$item['qty']."x ".$item['pretty']."\n
Extra: ".$item['message']."\n\n";
}
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
}
?>
HTML:
<form method="POST" action="neworder.php">
<div class ="item_left">
<img src="images/mexicantortas.jpg" border="2" width="200px" height="150px"><br>
Mexican Torta - $8.50<input name="item[]" type="hidden" value="torta"/>
<input name="pretty-name_torta" type="hidden" value="Mexican Torta"/><br>
How Many? <input name="quantity_torta" type="text" /><br>
<input name="message_torta" type="text" value="Enter special order instructions here..." />
</div><!-- ITEM_LEFT -->
<br />
<div class ="item_center">
<img src="images/fishsandwich.jpg" border="2" width="200px" height="150px"><br>
Fish Sandwich - $8.50<input name="item[]" type="hidden" value="fish"/>
<input name="pretty-name_fish" type="hidden" value="Fish Sandwhich"/><br>
How Many? <input name="quantity_fish" type="text" /><br>
<input name="message_fish" type="text" value="Enter special order instructions here..." />
</div><!-- ITEM_CENTER -->
<br />
<div class ="item_right">
<img src="images/hamburgers.jpg" border="2" width="200px" height="150px"><br>
Hamburger w/ Fries - $7.00<input name="item[]" type="hidden" value="hamburger"/>
<input name="pretty-name_hamburger" type="hidden" value="Hamburger"/><br>
How Many? <input name="quantity_hamburger" type="text" /><br>
<input name="message_hamburger" type="text" value="Enter special order instructions here..." />
</div><!-- ITEM_RIGHT -->
<br />
<div class="horizontal_form">
<div class="form">
<h2>Place Your Order Now: <font size="3"><font color="#037B41">Fill in the form below, and we'll call you when your food is ready to be picked up...</font></font></h2>
<p class="name">
<input type="text" name="name" id="name" style="text-align:center;" onClick="this.value='';" value="Enter your name"/>
</p>
<p class="phone">
<input type="text" name="phone" id="phone" style="text-align:center;" onClick="this.value='';" value="Enter your phone #"/>
</p>
<p class="submit">
<input type="submit" value="Place Order" name="submit"/>
</p>
</div><!-- FORM -->
</div><!-- HORIZONTAL_FORM -->
</form>
If item has no values anywhere it wont get posted to the receiving page.
Use isset to check if the value exists and is_array to check if it's an array.