How to get the Name value using Post method in php like this
<input type="text" name="<?php echo $result['name'];?>" id="">
How to Post the Name value..?
<?php
$name=$_POST[''] --? here how can i get the value using name.
Please help me.Thanks
Is this Correct..?
$name=$_POST['$result['name']'];
<input type="text" name="<?php echo $_POST['name'];?>" id="">
this is the wrong way to generate name dynamically... but if you really want this way only then you can do it this way..
<input type="hidden" value=<?php echo $result['name'];?> name="abc"/>
<input type="text" name="<?php echo $result['name'];?>" id="">
don't forgot to check variable is set or not using isset()
in php
if(isset($_POST['abc']))
{
$abc=$_POST['abc'];
$original = $_POST[$abc];
}
Use form tag to post the values from form.
<form action=".." method="post">
<input type="text" name="<?php echo $result['name'];?>" id="name" name="name"/>
<input type="submit" value="submit"/>
</form>
In php to receive the value from form.
$n=$_POST['name'];
Related
Let's say I have a form that I send via GET:
<form method="get" action="/search.php?foo=bar&test=1&something=else">
<input type="text" name="day" placeholder="day"/>
<input type="text" name="link" placeholder="link"/>
</form>
And after submitting my form and processing the data (which consists of only saving it to a file), the url is changed to:
search.php?day=test&link=google.com
What should I do so the url becomes:
/search.php?foo=bar&test=1&something=else&day=test&link=google.com
(preserving the old parameters that were included in action attribute.)
The form action will change every time and it's difficult to keep the old GET parameters in the form action.
However, you can go with hidden fields.
Try this:
<form method="get" action="/search.php">
<input type="hidden" name="foo" value="bar"/> <!-- Add this -->
<input type="hidden" name="test" value="1"/> <!-- Add this -->
<input type="text" name="day" placeholder="day"/>
<input type="text" name="link" placeholder="link"/>
</form>
You could try changing the action before submitting, depending how you're going to submit the form. This can be done if you apply IDs to your texts and either a name or an ID to the form.
HTML:
<form id="frm" method="get" action="/search.php?foo=bar&test=1&something=else">
<input type="text" name="day" id="day" placeholder="day"/>
<input type="text" name="link" id="link" placeholder="link"/>
</form>
Then with JavaScript you can run a function and change the form's action:
var _form = document.getElementById('frm');
var day = document.getElementById('day').value;
var link = document.getElementById('link').value;
_form.action += '&day=' + day + '&link=' + link;
_form.submit();
You could try to use a hidden input field.
<input type="hidden" name="name" value="value">
if you are getting your variables first from get and then want to add into 2nd form you could get this and create input fields hidden with these get values
Now when you submit form in get url you will get all you desire data
<?php
if($_GET){
if(isset($_GET['submit1'])){
$foo = $_GET['foo'];
$test = $_GET['test'];
$something = $_GET['something'];
?>
<form method="get" action="/search.php">
<input type="hidden" name="foo" placeholder="foo" value="<?php echo $foo; ?>"/>
<input type="hidden" name="test" placeholder="test" value="<?php echo $test; ?>"/>
<input type="hidden" name="something" placeholder="something" value="<?php echo $something; ?>"/>
<input type="text" name="day" placeholder="day"/>
<input type="text" name="link" placeholder="link"/>
</form>
<?php
}
}
?>
I am trying to understand how to use the $_GET function. I am using a form from my CRM system Infusionsoft. I have a few different ads running to this form from different sources. I use UTM's to keep track of where people are coming from.
Example URL UTM: http://www.awesome.com/?utm_source=google&utm_medium=cpc&utm_term=keywords&utm_content=content&utm_campaign=name
The hidden field was my attempt to try to pull the data and pass it along when the form is submitted. Unfortunately it is not working and I am a bit of a newbie to php.
<form accept-charset="UTF-8" action="https://mk165.infusionsoft.com/app/form/process/ff023ed2f8ffd7c46b03cdc50a115e93" class="infusion-form" method="POST" name="myForm" onsubmit="return validateForm()">
<input name="inf_form_xid" type="hidden" value="ff023ed2f8ffd7c46b03cdc50a115e93" />
<input name="inf_form_name" type="hidden" value="Ninh Neuropathy" />
<input name="infusionsoft_version" type="hidden" value="1.48.0.46" />
<input type="hidden" id="inf_custom_GaSource" name="inf_custom_GaSource" value='<?php echo $_GET['utm_source']?>'/>
<input type="hidden" id="inf_custom_GaMedium" name="inf_custom_GaMedium" value='<?php echo $_GET['utm_medium']?>'/>
<input type="hidden" id="inf_custom_GaTerm" name="inf_custom_GaTerm" value='<?php echo $_GET['utm_term']?>'/>
<input type="hidden" id="inf_custom_GaCampaign" name="inf_custom_GaCampaign" value='<?php echo $_GET['utm_campaign']?>'/>
<input type="hidden" id="inf_custom_GaContent" name="inf_custom_GaContent" value='<?php echo $_GET['utm_content']?>'/>
<input class="infusion-field-input-container" placeholder="First Name" name="inf_field_FirstName" type="text" />
<input class="infusion-field-input-container" placeholder="Last Name" name="inf_field_LastName" type="text" />
<input class="infusion-field-input-container" placeholder="Phone" name="inf_field_Phone1" type="text" />
<input class="infusion-field-input-container" placeholder="E-mail" name="inf_field_Email" type="text" />
<input class="infusion-field-input-container submit" id="submit" name="" value="Get In Touch Today" type="submit" />
</form>
Your form method is POST so when you submit the form you will get the values in php as:
<?php
print_r($_POST);
?>
You will get the all form input values in $_POST Super Global included all hidden inputs.
One last thing also use double quotes in hidden input values instead of single quotes as:
<input type="hidden" id="inf_custom_GaSource" name="inf_custom_GaSource" value="<?php echo $_GET['utm_source'];?>"/>
Often both types of parameters are needed. It might make things easier if GET and POST parameters are normalized and then can be accessed in a unique way like this:
$params = array();
foreach ($_GET as $k=> $v) $params [$k] = $v;
foreach ($_POST as $k=> $v) $params [$k] = $v;
echo $params['myvalue'];
I am using dynamic form where user add more input text boxes for a certain field he want and the name of each box change with an increment like:
<form method="post" action="somescript.php">
<input type="text" name="textbox" />
<input type="text" name="textbox1" />
<input type="text" name="textbox2" />
<input type="text" name="textbox3" />
.... and so on
</form>
I want to echo these data following a loop:
<?PHP
$k=$_POST['counter']; //counter value coming as post variable
for($i=1$i<=$k;$k++){
echo $_POST['textbox'.$i]; //something like this......?
}
?>
Please reply.
Use array notation instead.
<form method="post" action="somescript.php">
<input type="text" name="textbox[]" />
<input type="text" name="textbox[]" />
<input type="text" name="textbox[]" />
<input type="text" name="textbox][" />
.... and so on
</form>
When the form is submitted, $_POST['textbox'] will then be an array, and you can loop over it:
foreach ($_POST['textbox'] as $textbox) {
echo $textbox;
}
I just came across this issue because I had blocks of data that needed to be created dynamically and
echo $_POST["textbox$i"];
worked without the concatenation in it. Let me know if this is bad practice, it works in my situation though. The array way didn't work for me. Sorry for posting this on a 3 year old question. I'm not sure if that's bad practice. Thanks.
i assign a text box value from a php variable and now i need to pass that value to another form, i'm able to receive other text box values in another page but couldn't get the value of the text box which i assigned using php variable...
<form name="form1" action="book.php" method="post">
<input type="text" name ="name" id="name" value="XXX">
<input type="text" name="da" id="da" value='<?php echo $output?>'>
<input type="submit" value="BOOK" name="book" onClick="return validate()">
</form>
in book.php
if(isset($_POST['book']))
{
$da = $_POST['da'];
$name= $_POST['name'];
echo "$name";
here i get the value for name but not for da...
You need a semi-colon after the PHP echo command:
<input type="text" name="da" id="da" value='<?php echo $output; ?>'>
I've got a php variable like so.. $name = $_REQUEST['name']; I'd like to put it in a HTML form field's value e.g in here.. <input type="text" name="name" value=(php variable here) />
How would I do so?
Thanks.
value="<?php echo htmlspecialchars($name); ?>"
You can do it like this,
<input type="text" name="name" value="<?php echo $name;?>" />
But seen as you've taken it straight from user input, you want to sanitize it first so that nothing nasty is put into the output of your page.
<input type="text" name="name" value="<?php echo htmlspecialchars($name);?>" />