Open new page with post data - php

In PHP, i want to open more that one window and each one of them need to recieve different post data.
i know how to redirect a page via header location + Get DATA, but i really need to be able to send POST data.
EDIT:
Graph
|-Page with post 1
Main --|-Page with post 2
|-Page with post 3
so basically 1 page goes and open 3 pages with different post data on each. must be done server Side.

why not use three forms? ;-) Code tested, works.
<form method='post' action='http://<sever>/post1.php' id='action_frm1' name="action_frm1" target="_blank">
<input type='hidden' name='param1' value='hello'/>
<input type='hidden' name='param2' value='world'/>
</form>
<form method='post' action='http://<sever>/post2.php' id='action_frm2' name="action_frm2" target="_blank">
<input type='hidden' name='param1' value='hello2'/>
<input type='hidden' name='param2' value='world2'/>
</form>
<form method='post' action='http://<sever>/post3.php' id='action_frm3' name="action_frm3" target="_blank">
<input type='hidden' name='param1' value='hello3'/>
<input type='hidden' name='param2' value='world3'/>
</form>
<script type='text/javascript'>
function makePostRedirect() {
document.getElementById('action_frm1').submit();
document.getElementById('action_frm2').submit();
document.getElementById('action_frm3').submit();
}
makePostRedirect()
</script>
Of course, if you want post data via serverside usefull link will be this: http://noobflash.com/server-side-post-with-php/

you may use the following trick:
<form method='post' action='action.php' id='action_frm'>
<input type='hidden' name='param1' value='hello'/>
<input type='hidden' name='param2' value='world'/>
</form>
<script type='text/javascript'>
function makePostRedirect() {
document.getElementById('action_frm').submit();
}
</script>

You will need to do a workaround by calling window.open to some stub PHP pages that can then use some JavaScript to call a form post. What your asking can not really be done in PHP because PHP is server side and not front end. Your looking for a much more JavaScript reliant solution.

You can do a single POST to a new window by putting a target="_new" on the <form> element. It won't validate, but it will open ONE new window and submit the form data via that window.
For multiple windows, you'll have to hack together some JS to open the multiple windows, insert a form with a copy of the data you want to have posted in that window, then trigger the posts individually.

how about this:
Original page ---opens---> page 1 ---opens---> page 2 ---opens---> page 3
Each page passes the data for the remaining pages. Search for javascript pop-up code that works and runs on page open.

Related

PHP not receiving all POST data

I have a really long form, which is basically a sign up for a college. And it's been working fine, although for some reason now I am not able to receive the POST data for the form anymore. I seem to receive all the variables, expect for the 'SUBMIT' button, which is what I look for to find out that it's posted.
It's a sliding form, meaning that it's about 450px high and it is split up into different 'pages', and at the bottom of each page there is previous, save for later, and next buttons. The previous and next activate jQuery functionality which slides the form left or right. The save for later button is a submit button which puts any received data into the database for retrieval later. The HTML for these buttons is:
<input type='button' class='previous' value='Previous'>
<input type='submit' class='saveforlater' name='saveforlater' value='Save For Later'>
<input type='button' class='next' value='Next'>
All three of these buttons work fine, if I test the receiving of saveforlater in PHP like so:
if(isset($_POST['saveforlater'])) {
// Do Stuff
}
It works every time.
However, right at the end of the form I have this:
<input type='button' class='previous' value='Previous'>
<input type='submit' class='next send' name='sendapplication' value='Send Application'>
And It used to work, but I cannot figure out what I've changed in order to stop it working. If I var_dump($_POST), I get all the other variables, except for this button.
So if I try to:
if(isset($_POST['sendapplication'])) {
I get nothing. NOTHING! I don't know why :(. It's such a simple thing and it's frustrating me.
If you click this button, you will see with var_dump or debug() returns this variable.
For submit buttons inside <form>, only buttons clicked will be setted as $_POST variable with its value.
Your input should have the attribute name. Your html should look like
<input type='button' class='previous' name='previous' value='Previous'>
<input type='submit' class='saveforlater' name='saveforlater' value='Save For Later'>
<input name='saveforlater' type='button' class='next' value='Next'>
Your php should look like in /enrol
<?php
var_dump($_POST);
Hope this helps you
How many fields are there in your form??
I think it is the problem due to size of limited post request. It is the problem of server configuration.
If you want to control it refer following link
What is the size limit of a post request?
If you're using a HTML form to send the data and a localhost server, your attribute action needs to have the PHP file directory on the server.

How to change a PHP variable with a HTML button click?

I am trying to change a PHP variable with either a HTML button click, or another appropriate way.
Unfortunately, I am unable to post a majority of my code here, but I'll supply as much as possible.
Firstly, I have two buttons on my site. They each call two different javascript functions, but they load the same HTML form. The form is then submitted to a MySQL database, depending on which button was clicked at the beginning.
Instead of having both the buttons load the same form, I would like them to load different forms. I would like to do this by saving a PHP variable when the user clicks on either button.
I have searched online quite a bit, but I found no direct answer to my question.
Here is a slight example:
HTML button to add a quiz:
<h2>
<button id='opener' class='roundButton add' value='' onClick="OpenNewQuizDialog();">
</button>
Create Quiz
</h2>
HTML button to add a presentation:
<h2>
<button id='opener' class='roundButton add' value='' onClick="OpenNewPresDialog();
</button>
Add Presentation
</h2>
Both Javascript functions:
function OpenNewQuizDialog()
{
$( "#dialog" ).dialog( "open" );
$('#dialog').dialog({title:"Create Quiz"});
$('#dialogtype').val("addquiz");
}
function OpenNewPresDialog()
{
$( "#dialog" ).dialog( "open" );
$('#dialog').dialog({title:"Create Presentation"});
$('#dialogtype').val("addpres");
}
The HTML Form that is being opened:
<div id="dialog" title="Edit Settings">
<form name="editForm" method="post" action="createplay.php">
<input type=hidden id='dialogid' name='dialogid' value=''>
<input type=hidden id='dialogtype' name='dialogtype' value=''>
<input type=hidden id='uid' name='uid' value='<?php echo $userid; ?>'>
<div>
Name: <input type='text' id='nameEdit' name='nameEdit' value=''>
</div>
<div>
Data: <textarea id='textEdit' name='textEdit' row='10' cols='50'></textarea>
</div>
<input type="submit" class="roundButton upload" value="" />
</form>
</div>
What I have tried:
I tried adding the following into the onClick part within the HTML buttons:
quiz button: <?php $create_type = 'createquiz' ?>
presentation button: <?php $create_type = 'createpres' ?>
I then tried to make an 'if' statement to see which button was clicked, so I could show the appropriate form. Although, the value of $create_type was always 'createpres' since it was being called last on the page. It was like the PHP was being called, even though the HTML onClick was not being called.
Is there a better way to approach this?
PHP is a server side language while Javascript runs in client. That means they both run separately. But if you would like them to process together, such as getting data to be displayed using javascript, you will have to use AJAX.
There is no need for the extra variables as you set a form control with the appropriate value
$('#dialogtype').val("addquiz");
The form will receive this value:
<input type=hidden id='dialogtype' name='dialogtype' value=''>
Now it is up to your php script (createplay.php) whether the $_POST['dialogtype'] == 'addquiz' ) or the other value and process the data as intended
You can't create a php variable via html as php is server side and html is client side. :)

Sending data with post method to another site

I wanna send some variables to another server with post method. I made a code and it worked on my localhost. But I cannot made it work for another site.
<form name='myform' action='#' method='POST'>
<input type='hidden' name='intnumber' value='15'>
<a id='Link' onclick='document.myform.submit()' href='#'>Go!</a>
</form>
I wanna get keywords to my site automaticly. I use Ubersuggest site manual but it takes long time add keywords manually. So, I wanna send ubersuggest.org post form to search keywords and take the keywords with php bot. I prepared a code for search part, it is not working:
<form name='uberform' action='http://www.ubersuggest.org/' method='POST'>
<input type='hidden' name='query' value='game'>
<input type='hidden' name='language' value='English/UK'>
<input type='hidden' name='source' value='web'>
<a id='Link' onclick='document.uberform.submit()' href='#'>Go!</a>
</form>
Please help me for correcting this code.
NOTE: I want to use this site just personally, i will not make any profit. And I dont want attack etc. to this site, cos' i love it and i use it!
Try using http://php.net/manual/en/book.curl.php. Post to other domains is not allowed.

How do I submit my form using href?

Am using this onclick='document.forms['form_name'].submit(); return false;' but this doesn't work as am having href=results.php?page_no=1 etc, has dynamic links, examples show to make this work I need to use href="#" but any idea how I can submit the form and than navigate to page2? Because I want to save the check box values in a session
Add class to your hrefs (class="pagination") and id (id="form") to your form. Then you can use Jquery framework for this stuff.
$(".pagination").click(function(){
// get page id, set form action with params
$("#formId").submit();
return false;
});
You have a bad design.
You can't perform multiple competing actions on a form click and expect it to work.
You need to either let the link be clicked and let it load another page, or if you are just setting some session variable (although it would be far better to set this with a querystring parameter or a cookie), you can use an Ajax request to send that off asynchronously.
Here I substituted page2 with Google just for test
Submit
<form method="get" action="https://www.google.com/search?q=test" name="test">
<input name="Checkbox1" type="checkbox" />
</form>
edit:
Submit
<form method="get" action="" name="test">
<input name="Checkbox1" type="checkbox" />
</form>
without encodeURIComponent(this.getAttribute('href') the parameters are missed.
Some options:
1) Use jQuery AJAX, serialize and post the form data and then redirect (location.href) on the onSuccess callback. Something like this:
$.post("submitform.php",
$("form").serialize(),
function(data){location.href='results.php?page_no=2';}
);
2) Post the form to a named hidden iFrame using "target" on the form tag. If this is really just a best effort sort of recording you shouldn't need to wait for the page to load, the request should be enough and you can continue to the next page. Something like this:
<iframe="targetname" style="display:none;" />
<form name="myform" target="targetname" method="post" action="submitform.php">
....
</form>
<a href="page2.php" onClick="document.forms['myform'].submit(); return true;">
Click Here
</a>

Loading MySQL Data into Existing Form Without Page Reload

I have a form on a page that is used to "Add/Edit a Location". Here is my form:
<form id='locationEditForm' name='locationEditForm'>
<table width='50%'>
<tr><td colspan='2'><hr></td></tr>
<tr><td colspan='2'><button type='submit' name='save' id='save'>Lookup Location By ID: </button>
<input type='text' size='10' name='locationToEdit'><br/><br/></td></tr>
<tr><td>Name:</td><td><input type='text' name='locationName'/></td></tr>
<tr><td>URL:</td><td><input type='text' name='locationURL'/></td></tr>
<tr><td>Coordinates:</td><td><input type='text' name='locationCoords'/></td></tr>
<tr><td>Address:</td><td><textarea name='locationAddress' rows='4' cols='40'></textarea></td></tr>
<tr><td>Phone:</td><td><input type='text' name='locationPhone'/></td></tr>
<tr><td>Hours:</td><td><textarea name='locationHours' rows='3' cols='40' wrap='soft'/></textarea></td></tr>
<tr><td colspan='2'><button type='submit' name='save' id='save'>Save Changes</button>
<button type='button' class="cancel">Cancel</button></td></tr>
</table>
</form>
I've wrapped the form elements in a table just for the sake of keeping the input boxes aligned for now in a "quick and dirty" sort of way.
Anyway, As you can see, I have a button and input area for the user to "lookup" an existing location by id. This is so that an existing location can be edited. I understand how to make that button 'submit' to my php code and to then lookup the location in the database, but my question is this -- is it possible to lookup the location in a MySQL database and load the information into the existing form without causing the page to reload as it normally would when I post the form?
Ideally, I imagine the data for an existing location just "popping" into the form without the entire page reloading. How would I go about doing something like this?
Thanks a ton!
The technique you're looking for is commonly referred to as Ajax. In your case, you'd want to submit an XMLHttpRequest() to a different PHP script which returns data you can use. Either HTML to insert into your form, or JSON data which you parse and use to update field values would be good choices.
There are lots of resources out there on how to make a PHP/MySQL endpoint for an Ajax request. These search terms should get you started. Good luck!
Indeed it is, you have to use javascript though. I would advise you to take a look at Jquery. And it's $.ajax and $.post functions.

Categories