I have a form like this :
$form = '<form action="https://www.zarinpal.com/users/pay_invoice/'.$res.'"
method="post" target="_parent" ><input type="submit" value="Buy"/></form>';
$form .= '</form>';
echo $form;
I want to add a function to this form, so when "Buy" is clicked, then in MySQL a database is created for this user with the information of the selected item and his account id with a pending transaction status, and then the form redirects him to the webpage included.
I can manage the MySQL part, but the form only redirects the user to the given webpage, and i can not add users information to the database.
Is there a way I can add a database row for this user, then redirect him to the payment webpage ? ( except creating another page )
<form action="https://www.zarinpal.com/users/pay_invoice/<?=$res ?> method="post" target="_parent" >
<input type="test" name="customer-name" />
<input type="submit" value="Buy"/>
</form>
Then on the target page put:
<?
print_r($_POST);
## That will let you know what is being posted from the form
?>
To access the 'customer-name' variable for example just do:
$customerName = $_POST["customer-name"];
Related
I am working on a restaurant search and review project. I have a search page that will show restaurant names and provides a link for the user to add a review for each restaurant result by using the hidden input rid.
In my review.php, I am using the value sent in for the hidden input rid to run another simple query and then display the name of the restaurant. Then I have several inputs so the user can input their name, their rating of the restaurant, and finally a comment.
<form action="comment.php" method="GET">
<INPUT TYPE="hidden" NAME="rid" VALUE="">
<?php
$db=mysqli_connect(//parameters);
$restaurant_id= $_GET['rid'];
if (!empty($_GET)){
$result = $db->query(//query);
$row = $restaurant_result->fetch_assoc()
echo $row["name"];
}
?>
<INPUT //other inputs for the user>
</form>
My problem is that when the user hits a submit button at the bottom, the page will refresh with the url www..../review.php?rid= meaning that the name of the restaurant can't be displayed since no restaurant id parameter is being resent in the form. How can I send the restaurant id back to the page again once it is done?
I tried the top answer in this thread but I get the same url problem: Pass parameter to form action in HTML
<INPUT TYPE="hidden" NAME="rid" VALUE="<?php if(isset($_GET['rid'])){echo $_GET['rid'];} ?>">
my page receives data which i retrieve with $_post. I display some data and at the bottom of page my button has to save data to mysql. I could submit form to next page, but how do i access the data that I have retrieved with post then? Lets say i have following code (in reality alot more variables ..):
<?php
$v= $_POST["something"];
echo $v;
echo "Is the following information correct? //this would be at the bottom of the page with the buttons
?>
<input type="button" value="submit data" name="addtosql">
You can do it in two methods:
1) You can save the POST variable in a hidden field.
<input type="hidden" name="somevalue" value="<?php if(isset($_POST["something"])) echo $_POST["something"];?>" >
The hidden value also will get passed to the action page on FORM submission. In that page you can access this value using
echo $_POST['somevalue'];
2) Use SESSION
You can store the value in SESSION and can access in any other page.
$v= $_POST["something"];
session_start();
$_SESSION['somevalue']=$v;
and in next page access SESSION variable using,
session_start();
if(isset($_SESSION['somevalue']))
echo $_SESSION['somevalue'];
Take a look. Below every thing should be on single php page
// first create a function
function getValue($key){
if(isset($_POST[$key]))
return $_POST[$key];
else
return "";
}
// process your form here
if(isset($_POST['first_name']){
// do your sql stuff here.
}
// now in html
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="first_name" value="<?php echo getValue("first_name"); ?>" />
<input type="submit" />
</form>
I have written a script in php to replace in newtopic button in phpbb3
in other question, a user says me this:
In your submit.php, you can retrieve the forum ID using $_GET['f']. Now, to pass it on to application.php, you can use a hidden input field:
<form method="post" action="application.php" accept-charset="utf-8" >
$id = htmlspecialchars($_GET['f']);
<input type="hidden" name="forum_id" value="<?php echo $id; ?>"/>
When you click on the submit button, the forum ID value will also get POSTed, and you'll be able to retrieve it in application.php code using the $_POST['forum_id'].
and my code goes as here:
<form method="post" action="application.php" accept-charset="utf-8" >
$id = htmlspecialchars($_GET['f']);
<input type="hidden" name="forum_id" value="<?php echo $id; ?>"/>
.............
<fieldset class="submit-buttons">
<input value="Submit" class="button2" type="submit">
</fieldset>
This code is embedded in submit.php to use phpbb3 template.
and application.php goes as here
So I click on new topic button, and I redirect to submit.php?mode=post&f=3 and in that php there is embedded the html, the problem is that with the solution, I receive the next error:
"The forum you selected does not exist" and the addresswar goes as: viewforum.php?f=&sid=a69fb9f491d2adc11c4be3a6dac02774
so I think that forum_id (in thos case is "3" (&f=3) is not correctly sent throught php scripts
I would appreciate some help
You need to add $id = htmlspecialchars($_GET['f']); inside the <?php ?> tag,
<?php $id = htmlspecialchars($_GET['f']); ?>
I am working on a configuration proces with 6 steps. In each step I use a form which I submit and save the input data in SESSION variables.
On each step I have a "next button" which needs to submit the form of the page and redirects to the next step.
This piece of code checks if the submit button "wz_submit1" isset, then save the variables.
if(isset($_POST['wz_submit1'])) :
// Save wz_width in session
$wz_width = $_POST['wz_width'];
$_SESSION['wz_width'] = $wz_width;
// Save wz_height in session
$wz_height = $_POST['wz_height'];
$_SESSION['wz_height'] = $wz_height;
endif;
This is the "next" button:
<a class="wz_next_button" href="http://www.mynextstepurl.test">Next step</a>
This is my form:
<form id="wz_form1" method="post">
<ul class="wz_input">
<li>
<label>A</label>
<input name="wz_width" id="wz_width" type="text" value="<?php if(isset($_SESSION['wz_width'])) : echo $_SESSION['wz_width']; endif; ?>" />
<span>mm</span>
</li>
<li>
<label>B</label>
<input name="wz_height" id="wz_height" type="text" value="<?php if(isset($_SESSION['wz_height'])) : echo $_SESSION['wz_height']; endif; ?>" />
<span>mm</span>
</li>
</ul><!--End wz_input-->
<input name="wz_submit1" type="hidden" />
</form>
If I use a normal submit button for "wz_submit1" it submits the form right and saves the variables in session. But after that there's no redirect to next page.
If I put a onclick form submit on the "next" link, the redirect to next page goes right but my variables doesn't get set.
I hope you understand my problem and hope you can help me.
If you have a better idea on how doing it (for example without a form for each page) then let me know.
Thanks!
you can do it this way... when form submits and all the variable gets saved then it will redirect to your next page...
if(isset($_POST['wz_submit1'])) :
// Save wz_width in session
$wz_width = $_POST['wz_width'];
$_SESSION['wz_width'] = $wz_width;
// Save wz_height in session
$wz_height = $_POST['wz_height'];
$_SESSION['wz_height'] = $wz_height;
header('Location : www.yournextpage.com');
endif;
your next button and from will be...
<form method="post" action="samefile.php">
//your other fields
<input type="submit" value="next" name="wz_submit1"/>
</form>
i am retrieving data form database using a search query.
PHP code (which I'm using in search query to display search results)
echo "<span style='background-color= #FFFF00'>$query</span><br>";
$count=$dbo->prepare($query);
$count->execute();
$no=$count->rowCount();
if($no > 0 ){echo " <span>No of records = ".$no."</span>";
echo "<table><tr><th>PHONE NUMBER</th><th>OWNER NAME</th></tr>";
foreach ($dbo->query($query) as $row){
echo "<tr><td>$row[ROLLNO]</td><td>$row[CNAME]</td></tr>";
}
echo "</table>";
i want to do like this,
when a user clicks on a phone number, it should redirect to a new page and in that new page, my input box should be filled with this phone number and should be submitted.
Input Box Code (which I'm using in page 2)
<form name="phone_number_form" id="phone_number_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return vali()" >
<input type="text" name="number" id="number" />
<input type="submit" name="submit" value="Submit" />
</form>
Looking at w3schools PHP has a $_POST variable which is used to collect values from a form sent with method="post". There's also $_GET and $_REQUEST which seems to merge both post and get data. http://www.w3schools.com/php/php_post.asp
There are a couple of options like making a request (get) from your first page or post the data from your first page.
REQUEST Method
Heres how I think the request way to do it would work
PAGE 1
Amend the foreach that renders the table row to include an hyperlink to your second page
foreach ($dbo->query($query) as $row){
echo "<tr><td>$row[ROLLNO]</td><td>$row[CNAME]</td></tr>";
}
PAGE 2
Amend the textbox to be populated with the phone number from the request variable
<input type="text" name="number" id="number" value="<?php echo $_REQUEST["phoneno"]; ?>" />
POST Method
In your first page using javascript when the user clicks the phone number set a hidden field and submit the form to the second page. Again you should be able to read the hidden fields value from the $_REQUEST variable