I have block:
<div>
<input type="text" name="account[surname][]">
<input type="text" name="account[address][]">
<input type="text" name="account[phone][]">
...
<input type="number" name="account[number][][1]">
<input type="number" name="account[number][][2]">
<input type="number" name="account[number][][3]">
</div>
After submit i get:
{"id":{"13":""},"surname":{"13":"Mike"},"number":{"13":{"1":"623"},"14":{"2":"432"},"15":{"3":"542"}}}
But i need:
{"id":{"13":""},"surname":{"13":"Mike"},"number":{"13":{"1":"623","2":"432","3":"542"}}}
Id - Auto Increment.
Every "account[number][]" create new array. How can I put this data into an one array?
This form is added dynamically (clone).
For static form work this code, but i need dinamic:
<form>
<input type="text" name="account[surname][10]">
<input type="text" name="account[address][10]">
<input type="text" name="account[phone][10]">
...
<input type="number" name="account[number][10][1]">
<input type="number" name="account[number][10][2]">
<input type="number" name="account[number][10][3]">
<button type="submit">Send</button>
</form>
Related
For example below code, I have to click on submit button to go to the destination post page, but I want to go to the destination page without click on the submit button, and I want to go to the destination page with click on the button in my telegram bot an run my code page.
<html>
<body>
<form action="?????????" method="post" target="_blank">
type: <input type="text" name="type" value="111" ><br>
amount: <input type="text" name="amount"value="1000"><br>
cellphone: <input type="text" name="cellphone"value="2222"><br>
email: <input type="text" name="email"value="111#gmail.com"><br>
webserviceId: <input type="text" name="webserviceId"value="34433"><br>
redirectUrl: <input type="text" name="redirectUrl"value="w2323.php"><br>
issuer: <input type="text" name="issuer"value="ssdsd"><br>
redirectToPage: <input type="text" name="redirectToPage"value="True"><br>
scriptVersion: <input type="text" name="scriptVersion"value="Script"><br>
firstOutputType: <input type="text" name="firstOutputType"value="get"><br>
secondOutputType: <input type="text" name="secondOutputType"value="get"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Add an id to the form, then bind a function on a button. Although your question is a bit unclear on what you want exactly
<form id='someid'>
type: <input type="text" name="type" value="111" ><br>
amount: <input type="text" name="amount" value="1000"><br>
cellphone: <input type="text" name="cellphone" value="2222"><br>
email: <input type="text" name="email" value="111#gmail.com"><br>
webserviceId: <input type="text" name="webserviceId" value="34433"><br>
redirectUrl: <input type="text" name="redirectUrl" value="w2323.php"><br>
issuer: <input type="text" name="issuer" value="ssdsd"><br>
redirectToPage: <input type="text" name="redirectToPage" value="True"><br>
scriptVersion: <input type="text" name="scriptVersion" value="Script"><br>
firstOutputType: <input type="text" name="firstOutputType" value="get"><br>
secondOutputType: <input type="text" name="secondOutputType" value="get"><br>
<button onclick="myFunc()">
</form>
JS
function myFunc() {
document.getElementById("someid").submit();
}
I have a form:
<form>
<input type="text" name="aaa" id="aaa">
<input type="submit">
</form>
I have also jQuery script and can append this input.
Example:
Generating name.
<form>
<input type="text" name="aaa" >
<input type="text" name="aaa2" >
<input type="text" name="aaa3" >
<input type="submit">
</form>
Problems is MySQL insert:
How to insert from generated names?
I know $_POST['aaa'], but I don't know from generated names.
If you're generating dynamically text boxes from jQuery and you want to push them to mySQL, instead of creating them with names like 'aaa', 'aaa2' or 'aaa3' you can use square brackets like this:
<form method="POST">
<input type="text" name="field_name[]">
<input type="text" name="field_name[]">
<input type="text" name="field_name[]">
<input type="text" name="field_name[]">
<input type="text" name="field_name[]">
<input type="text" name="field_name[]">
<input type="text" name="field_name[]">
<button type="submit">Send</button>
</form>
That will allow you to use "field_name" as an array of strings.
<?php
$field_name = $_REQUEST['field_name'];
foreach($field_name as $value) {
$query = sprintf("INSERT INTO table SET field_name = '%s'", $value);
/* Execute Insert Query */
}
OK. if i have form like this:
<form method="POST">
<input type="text" name="aaa">
<input type="text" name="bbb">
<input type="text" name="ccc">
and i apend 3 input's
<input type="text" name="aaa">
<input type="text" name="bbb">
<input type="text" name="ccc">
<button type="submit">Send</button>
</form>
in mysql i have table:
id
aaa
bbb
ccc
this is one insert
I have a large amount of input fields. How can I pass the values into an array so I can pass the array from one page to another?
example:
<input type="text" value=<?php $arry = "compName" ?> placeholder="Company Name" />
Is this legal? How can I do this properly?
EDIT:
In my page, I have "add" and "delete" buttons that will add/delete more input fields. I also have a "preview" button at the bottom. User will add/delete before hitting preview. Preview will collect all input and will call the next page. So the amount of field is unknown.
Here's what my code/markup looks like:
<div class="panel" style="width: 98%; margin:0 auto">
<div class="row">
<div class="large-6 columns">
Advertiser Info: <hr>
<input type="text" value="compName" placeholder="Company Name" />
<input type="text" value= "adEmail" placeholder="Email" />
<input type="text" value="adContName" placeholder="Contact Name" />
<input type="text" value="adPhone" placeholder="Phone # (NO DASHES)" />
<input type="text" value="adStreet" placeholder="Street Address" />
<input type="text" value="adCity" placeholder="City" />
<input type="text" value="adState" placeholder="State/Provice" />
<input type="text" value="adZip" placeholder="Zip/Postal Code" />
<input type="text" value="adCountry" placeholder="Country" />
</div>
<div class="large-6 columns">
Billing Info: <hr>
<input type="text" value="bEmail" placeholder="Email" />
<input type="text" value="bContName" placeholder="Contact Name" />
<input type="text" value="bPhone" placeholder="Phone # (NO DASHES)" />
<input type="text" value="bStreet" placeholder="Street Address" />
<input type="text" value="bCity" placeholder="City" />
<input type="text" value="bState" placeholder="State/Provice" />
<input type="text" value="bZip" placeholder="Zip/Postal Code" />
<input type="text" value="bCountry" placeholder="Country" />
</div>
</div>
</div>
So when the user hits add and EXACT copy of above code will be made.
With that said, I want to be able to use PHP arrays for html values to pass. How can I set my inputs so that I can do this?
You can do some tweaks like:
Using input type elements as array elements.
So that:
<input type="text" name="elem[name]" value="<?php echo $YOUR_VALUE;?>"
<input type="text" name="elem[class]" value="<?php echo $YOUR_VALUE;?>"
<input type="text" name="elem[marks]" value="<?php echo $YOUR_VALUE;?>"
So that the variables are you are posting should be less.
In this case, you are posting only one variable instead of three.
Use Jquery to get all the values of input fields and make a json object of {input_name:value} or array variable of key value and then pass it in argument.
var key_value = {};
$('input').each(function(){
key_value[$(this).attr('name')]= $(this).val();
})
alert(JSON.stringify(key_value));
Now you have an object with field name as key and its value.
I have the following form:
<FORM action="http://url.to.mysite.com/doc.php" method="post">
<INPUT type="text" id="name">
<INPUT type="text" id="id">
<INPUT type="submit" value="Send">
</P>
</FORM>
Unfortunately, whatever is typed into the text fields, the PHP script receives only empty strings in every $_POST variable. All of the variables are set, just empty. What can be the cause of that?
You are missing the name properties in your html:
<FORM action="http://url.to.mysite.com/doc.php" method="post">
<INPUT type="text" name="name" id="name">
<INPUT type="text" name="id" id="id">
<INPUT type="submit" value="Send">
</FORM>
Only form elements with a name attribute will be sent to the PHP script (same with POST)
Try this:
<form action="http://url.to.mysite.com/doc.php" method="post">
<input type="text" id="name" name="name">
<input type="text" id="id" name="id">
<input type="submit" value="Send">
</form>
You need to add the name attribute to your input tags. Example: <input type="text" name="name" id="name" />
I have this Landing Page that I need to pre-populate with form values after it is submitted. Essentially in the end I have to make the url look like this...
http://example.com/r.php?sid=xx&pub=xxxxx&c1=&c2=&c3=&append=1&firstname=Test&lastname=Smith&address=2211+Commerce+St.&city=Dallas&state=TX&zipcode=75080&email=test#test.com
What I currently have now for the form is...
<form name="regForm" method="get" action="http://example.com/r.php?sid=xx&pub=xxxx&c1=&c2=&c3=&append=1">
<input id="firstname" class="text" type="text" name="firstname"/><br>
<input id="lastname" class="text" type="text" name="lastname" /><br>
<input id="email" class="text" type="text" name="email" /><br>
<input id="address" class="text" type="text" /><br>
<input id="city" class="text" type="text"/><br>
<input id="zipcode" class="text" type="text" maxlength="5" name="zipcode" /><br>
<input type="submit" value="Send Me My FREE List" id="submitBtn2"/>
</form>
How do i create that URL above after the form is submitted? I have been racking my brain all day on this and can't figure it out, i feel like im close.
thanks for the help!
Include the extra parameters as hidden form fields instead of inline query parameters:
<form name="regForm" method="get" action="http://example.com/r.php">
<input type="hidden" name="sid" value="xx" />
<input type="hidden" name="pub" value="xxxx" />
<input type="hidden" name="c1" value="" />
<input type="hidden" name="c2" value="" />
<input type="hidden" name="c3" value="" />
<input type="hidden" name="append" value="1" />
<input id="firstname" class="text" type="text" name="firstname"/><br>
<input id="lastname" class="text" type="text" name="lastname" /><br>
<input id="email" class="text" type="text" name="email" /><br>
<input id="address" class="text" type="text" /><br>
<input id="city" class="text" type="text"/><br>
<input id="zipcode" class="text" type="text" maxlength="5" name="zipcode" /><br>
<input type="submit" value="Send Me My FREE List" id="submitBtn2"/>
</form>
The problem is the input field get variables are causing your url get variables to be truncated, put all your url parameters as hidden values.
<input id="pub" type="hidden" name="pub" value=""/>
<input id="sid" type="hidden" name="sid" value=""/>
I'm assuming that you like the URL that it generates except that you're missing the sid, pub, c1, c2, c3, and append variables. If so, just make hidden inputs like this:
<form id="regForm" ...>
<input id="sid" name="sid" value="" type="hidden" />
<input id="pub" name="pub" value="" type="hidden" />
...
</form>
If you know the values while you're creating the form, then you can do it on the server side. If you don't, then assuming you're using jQuery, you will have to do something like this:
$(function() {
$('#regForm').submit(function () {
$('#sid').val('myNewSidValue');
$('#pub').val('myNewPubValue');
...
});
});