I have this HTML form:
<form action="" method="post">
<input type="hidden" name="data_first" value="9" />
<input type="hidden" name="data_second" value="2" />
<input type="hidden" name="date" value="2018-01-25" />
<input type="text" name="posted_data" value="0.1" />
</form>
I want combine this Posted data, with serialize function.
I can serialize only one input.
example: serialize($_POST['posted_data']);
I need function like this:
serialize($_POST['posted_data'],$_POST['data_first'],$_POST['data_second'],$_POST['date']);
Any ideas?
You can simply do -
serialize($_POST);
It will serialize all the posted data. And then process them accordingly.
Update
You can use input arrays -
<form action="" method="post">
<input type="hidden" name="data[data_first]" value="9" />
<input type="hidden" name="data[data_second]" value="2" />
<input type="hidden" name="data[date]" value="2018-01-25" />
<input type="text" name="data[posted_data]" value="0.1" />
</form>
And
serialize($_POST['data']);
Will serialize those specific inputs present in data.
there are two ways
1) By sending post array
e.g serialize($_POST)
2) By sending post data through array
e.g serialize(array($_POST['posted_data'],$_POST['data_first'],$_POST['data_second'],$_POST['date']));
Related
In this page : page.php?id=value
I've this html's code:
<form action="" method="get">
<input type="text" name="key" />
<input type="submit" name="send />
</form>
It's redirect me to: page.php?key=value , i want to redirect to: page.php?id=value&key=value , how i can do it? I must redirect it to this page with PHP ?
simply,
<form action="page.php" method="get">
<input type="hidden" name="id" value="<?php echo $value ?>">
<input type="text" name="key" />
<input type="submit" name="send" />
</form>
You can have the id as a hidden input in your form
<form action="" method="get">
<input type="hidden" value="<?php echo $my_id; /*Suppose this variable contain your value */ ?>" name="id" />
<input type="text" name="key" />
<input type="submit" name="send" />
</form>
put everything you want on the next page in your form:
<form action="page.php" method="get">
<input type="text" name="id" value="<?php echo $_REQUEST['id'];?>" />
<input type="text" name="key" />
<input type="submit" name="send />
</form>
Really though, you should be using POST to send data, and the above code is NOT secure (allows anything in a url to easily end up in a form that could create some sql injection or XSS type issues.
You need to have the form's action set to the page you want it to submit to. If it is blank it will just submit to the same page.
<form action="page.php?id=value&key=value" method="get">
<input type="text" name="key" />
<input type="submit" name="send />
</form>
I have the following form that is dynamically generated:
<form action="index.php?route=module/print_wizard/showPrintSheet&token=4ef5f4af6ba25d6096357fdb4809e819" method="post" enctype="multipart/form-data" id="form">
<input name="[print][6][1]" type="hidden" value="on">
<input name="[print][6][3]" type="hidden" value="on">
<input name="[info]" type="hidden" value="INV-GIS-00002-3">
<input name="[layout_override][6][1]" type="hidden" value="">
<input name="[layout_override][6][3]" type="hidden" value="">
<input name="[bundle_override][6][1]" type="hidden" value="">
<input name="[bundle_override][6][3]" type="hidden" value="">
<input name="[run_id]" type="hidden" value="14040455">
<button type="submit">Export</button>
</form>
My PHP code is:
var_dump($_POST);
echo "<HR>".$this->request->server['REQUEST_METHOD'];
I have done this a million times before and can not for the life of me figure out why my $_post array is empty. I have changed my post to a get and all the fields and values are passing, but I need to use a post. Do I need to have one visible form element? Please help!
You are not using valid names for your form fields:
<input name="[print][6][1]" type="hidden" value="on">
is not valid as it just has an array index but no name.
If you change it to for example:
<input name="print[6][1]" type="hidden" value="on">
it will work without any problems.
Please consider the following code,
<form action="index.php" method="post" name="adminForm" enctype="multipart/form-data">
<input type="hidden" name="showtime[]" id="showtime_1" value="1" />
<input type="hidden" name="showtime[]" id="showtime_2" value="2" />
<input type="hidden" name="showtime[]" id="showtime_3" value="3" />
<input type="hidden" name="mid" id="movie_id" value="100" />
.
.
.
</form>
I want to use ajax post to submit this.
$.post('index.php',{
'option':'com_movies',
'controller':'movie',
'task' : 'savedata',
'format':'raw',
'mid':$('#movie_id').val()
},function(result){
if(result)
alert(result);
return;
});
I want to know how I send showtime ids using ajax post.
You can use
$('input[name="showtime[]"]').serialize()
Which will give you all inputs with showtime name in format you can send by ajax...
Check on jsfiddle...
Demo
I'm rather aware that nested forms are invalid, I am building a simple form with php and which needs to contain another form that controls an ajax image upload box so that i can feed the filepath into the original form.
example code below;
<form>
<fieldset>
<input>
</fieldset>
<fieldset>
<input>
</fieldset>
<form action="js/ajaxupload.php" method="post" name="sleeker" id="sleeker" enctype="multipart/form-data">
<input type="hidden" name="maxSize" value="9999999999" />
<input type="hidden" name="maxW" value="400" />
<input type="hidden" name="fullPath" value="http://192.168.10.10:8080/intranet/dashboard/uploads/" />
<input type="hidden" name="relPath" value="../uploads/" />
<input type="hidden" name="colorR" value="255" />
<input type="hidden" name="colorG" value="255" />
<input type="hidden" name="colorB" value="255" />
<input type="hidden" name="maxH" value="200" />
<input type="hidden" name="filename" value="filename" />
<input type="file" name="filename" style="float:left; width:40% !important;" onchange="ajaxUpload(this.form,'js/ajaxupload.php?filename=name&maxSize=9999999999&maxW=200&fullPath=http://192.168.10.10:8080/intranet/dashboard/uploads/&relPath=../uploads/&colorR=255&colorG=255&colorB=255&maxH=300','upload_area','File Uploading Please Wait…<br /><img src=\'images/loader_light_blue.gif\' width=\'128\' height=\'15\' border=\'0\' />','<img src=\'images/error.gif\' width=\'16\' height=\'16\' border=\'0\' /> Error in Upload, check settings and path info in source code.'); return false;" />
</form>
<fieldset>
<input>
</fieldset>
<fieldset>
<input>
</fieldset>
<submit>
</form>
In previous project's I have just placed the image upload below the original form and fed the hidden inputs back into the original form, unfortunately that won't be possible for this project,
any ideas to get around this issue would be appreciated!
Is there any system to parse the External_form.pl to Internal_form.pl. For example:
Form.html
<html>
....
....
<form ... method="post" action="External_form.pl">
....
....
</form>
This form post values to External_form.pl
External_form.pl
It validates the Posted_Data and send this value again to Another Form Internal_Form.pl
Internal_Form.pl
It finally sends the data to (External.pl or to the Form.html) and processed the validated date at the backend.
Following is my sample form.
<form METHOD="post" METHOD="post" ACTION="index.php" METHOD="post" METHOD="post" METHOD="post">
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="submit" NAME="submit" VALUE="Submit" />
</form>
Basically I have 10 inputs of array. Assume my domain is http://domain.com and the file above is index.php. I am trying to fill the form automatically by using the following method.
http://domain.com/index.php?array[]=John&array[]=Kelly ... & array[]=Steven
Unfortunately, it is not working. :(
Have you tried something like this:
<?php
foreach( $_GET['array'] as $arr ) // Loop through the `array` variables of GET
echo '<input type="text" name="array[]" value="' . $arr . '" />'; // Display the the inputs
?>
However, please make sure that you use a cleaning function on $arr to prevent XSS. You will also need to check if $_GET['array'] is set or not, or PHP will whine about it.
Two things to try.
You are using the GET method with your example URL, but your form is set to POST. In your PHP, you may be looking for your data in $_POST when it's actually in $_GET. You can get data from both POST and GET using the $_REQUEST variable.
You may need to urlencode the []. ([] becomes %5B%5D when urlencoded.)
Lastly, a tip: when crafting links to send data through a GET query string, it is best practice to use & in place of the &'s in the URL.
If you are trying to fill the form from a GET request (your URL string), you have to get the values from the HTTP request in the $_REQUEST array (or $_GET or $_POST depending on the form method). Suggestion: you should change the names of the form fields to reflect the value they are storing
<form METHOD="post" METHOD="post" ACTION="index.php" METHOD="post" METHOD="post" METHOD="post">
<input TYPE="text" NAME="first_name" value="<?php echo $_REQUEST['first_name']?>"/>
Note: accessing the $_REQUEST array as shown above is not good practice as you need to check if the request variables are set before you can echo their values.
<form METHOD="post" METHOD="post" ACTION="index.php" METHOD="post" METHOD="post" METHOD="post">
<input TYPE="text" NAME="first_name" value="<?php echo isset($_REQUEST['first_name'])?$_REQUEST['first_name']:""?>"/>