and thanks for the great help your community provides.
Here is a question regarding Paypal. The code below creates a buy-now non-hosted button. I would like to be able to do run my geoTestArray.php code, currently simply included, as the user presses the Buy Now button, and not when the button is displayed on the page.
Is this possible at all?
Thanks in advance,
Joe
<?php
include ('geoTestArray.php');
echo "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">
<input type=\"hidden\" name=\"business\" value=\"shop#mysite.com\">
<input type=\"hidden\" name=\"cmd\" value=\"$cmd\">
<input type=\"hidden\" name=\"amount\" value=\"$price\">
<input type=\"hidden\" name=\"shipping\" value=\"$shipping\">
<input type=\"hidden\" name=\"currency_code\" value=\"$currency\">
<input type=\"hidden\" name=\"shipto\" value=\"$shipto\">
<input type=\"hidden\" name=\"item_name\" value=\"$title\">";
if ($cmd == 'cart') {
echo "<input type=\"hidden\" name=\"add\" value=\"1\">";
}
include('./quantities2.php');
echo "<input type=\"hidden\" name=\"lc\" value=\"US\">
<input class=\"submit\" type=\"image\" src=\"$button\" border=\"0\" name=\"submit\" alt=\"$altaction\">
<img alt=\"\" border=\"0\" src=\"https://www.paypal.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\">
</form>";
?>
You can display only a form with one input, for example item_id.
After submitting this form you search for item details, execute your geoTestArray.php in backend and after that you can redirect your users to paypal using header("location: $query");
here's how I would do:
<?php
if( isset($_POST['do_action']) && $_POST['do_action'] != "" ) {
//check for non-empty item_id field
//run your geoTestArray.php script
//get item details from database and build your paypal query
$query = "https://www.paypal.com/cgi-bin/webscr&cmd=_xclick"; // add rest of paypal request fields separated by &
header( "Location: $query" );
}
?>
<form action='' method='post'>
<input type='hidden' name='item_id' value'your_item_id'>
<input type='submit' name='do_action' value='Buy'>
<form>
Hope I helped you! :d
Thanks everyone for comments and solution options. I have eventually chosen to modify an onSubmit javascript I had on my page, by adding:
function InterceptForm(formObj) {
var newshipto = httpGet('geoTestArray.php');
formObj.shipto.value = newshipto;
}
The above code makes use of the httpGet() function posted in this other stackoverflow post:
HTTP GET request in JavaScript?
To complete the puzzle:
The code below is in the html in my page
<script language="javascript">
// During onLoad, loop through all forms and for each form object do something
function InterceptForm(formobj) {
formobj.onsubmit = function ff() {
interceptform(formobj);
};
}
</script>
The code below gathers all forms on the page and runs the above javascript on each (NOTE: you may want to name your forms so that you only run the script on the relevant forms and not on all forms):
<script language="javascript">
function GetForms() {
var formsCollection = document.getElementsByTagName("form");
for(var i=0;i<formsCollection.length;i++)
{
if (formsCollection[i].name != "seecart")
{
InterceptForm(formsCollection[i]);
}
}
return true;
}
</script>
The code below is the onLoad function:
<script language="javascript">
function onLoadFunction () {
GetForms();
return true;
}
</script>
Cheers,
Joe
Related
I am making a webpage that allows you to add friends. For the confirm part I made a confirm button that made a post redirect to the confirm page:
while($rs=$friendsToConfirm->fetch_row()) {
echo "Friends $count to confirm's ID: $rs[0]";
echo "
<form name=\"confirm\" method=\"post\" action=\"confirmfriend.php\">
<input type=\"hidden\" name=\"userID\" value=\"$userID\">
<input type=\"hidden\" name=\"friendID\" value=\"$rs[0]\">
<input type=\"submit\" value=\"Confirm\">
</form>
";
echo "<br>";
$count++;
}
The $friendToConfirm variable is all the friends needed to confirm and is retrieved from MySQL. When I hit the button, I was expected to receive the userID and friendID from confirmfriend.php, but I did not receive anything using $_POST['userID'];. Is there another way to do this or an I doing something wrong.
This is because all of your forms have the same name [confirm]. You can try this:
$sl = 1;
while($rs=$friendsToConfirm->fetch_row()) {
echo "Friends $count to confirm's ID: $rs[0]";
echo "
<form name=\"confirm{$sl}\" method=\"post\" action=\"confirmfriend.php\">
<input type=\"hidden\" name=\"userID\" value=\"$userID\">
<input type=\"hidden\" name=\"friendID\" value=\"$rs[0]\">
<input type=\"submit\" value=\"Confirm\">
</form>
";
echo "<br>";
$count++;
$sl++;
}
Hope this will work.
Both of your hidden input fields are called "userId". I imagine the 2nd one needs to be renamed to "friendId".
All of the forms will also have the same name. It is usually preferred to ensure form names are unique.
If $_POST ['userId'] exists but is blank, check that $userId isn't blank.
To debug you can just var_dump the post array.
I have a form that contains two button
but when I press on one of them nothing happen
and I can't find the problem can you help me please !!
here my php code :
<?php
session_start();
include 'connection.php';
// in this section, I retrieve data from database and display them on table
// if agree button pressed do the following
if (isset($_POST['agree']))
{
$que="update project set status='submitted' ,projectstatus=1 where projectid=$id ";
$result3=mysql_query($que);
if ($result3)
{
echo(" <script>
alert('The project has been approved');
</script>");
header( "Location:unsubmited.php" );
}
else
{
echo "an error occur can't agree on this project";
}
}
?>
and this is the form :
<form action='' method='post'>
<input type='button' name='disagree' value='disagree ' class='styled-button-11'>
<input type='button' name='agree' value='agree' class='styled-button-11'>
</form>
thanx ^^
Change your code for this, as it says andrewsi:
<form action='' method='post'>
<input type='submit' name='disagree' value='disagree ' class='styled-button-11'>
<input type='submit' name='agree' value='agree' class='styled-button-11'>
</form>
I believe this is as simple as, filling in the action='' to the page to post back to and setting the type='submit' as andrewsi suggested.
<?php
require "../db/dbconfig.php";
$gal=mysql_query("select * from gallery");
$numrows=mysql_num_rows($gal);
if($numrows>=1)
{
echo "<form action='delete.php' method='post' name='f2' id='f2'>";
echo '<table id="rqst" style="display:block;" border="0" cellpadding="12" cellspacing="3" width="500px">';
echo "<tr><th>Tick to select</th><th>Images in Gallery</th></tr>";
while($row=mysql_fetch_array($gal)
{
$imgfile=$row['ImgName'];
$Image="<img src=gallery/".$imgfile." width='230px' height='150px'/>";
$img_name=$imgfile;
echo "<tr>";
echo "<td><input type='checkbox' name='imgs[]' value='$img_name'></td><td>".$Image."</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan='3' align='right'>";
echo "<input type='submit' value='Delete' name='del'></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
?>
This is my code....This will display images from gallery and checkboxes associated with them. When I click delete button with unchecked checkboxes an alert should come like this "Please check at least one checkbox"..How to do that??
My next problem is,,when I click delete button after checked checkbox, alert should come like this=" Do you want to delete?? "...If clicked Ok,the image must be deleted else do nothing...Please help ...Thanks in advance....
check this below link for validation using jquery:
http://jsfiddle.net/susheel61/U3Unk/2/
<form id="form">
First name: <input type="checkbox" name="firstname" class="check"><br>
<button>test</button>
</form>
$("button").on("click",function(e){
var status = $(".check").is(":checked");
e.preventDefault();
if(!status){
alert("this is not checked");
}
});
Yes, you can do it by javascript or jquery to validate whether your atleast one checkbox is select or not. So, for that you need to give a common class for all checkbox as example
<input type="checkbox" name="firstname" class="addchk">
Now in your submit button call a javascript function which validate the matter.
<input type='button' value='Delete' name='del' onclick='delete_checked()' />
Now write a function to validate whether any checkbox is selected.
function delete_checked()
{
var status = $(".addchk").is(":checked");
e.preventDefault();
if(!status){
alert("this is not checked");
}
else
{
// SUbmit yout form
}
}
This is the code for the php file containing the form with radio buttons:
<?php
while($r7 = mysql_fetch_array($rt3)){
$name=$r7["name"];
$s=$r7["question"];
echo "
<div>$s</div>
<form name='Tester' method='post' onSubmit='return RegValidate(this);' action='quest.php' >
<input type='radio' name='w1' value='1'>1<br>
<input type='radio' name='w1' value='2'>2<br>
<input type='radio' name='w1' value='3'>3<br>
";
}
echo" <input name='Submit' value='Tester' type='submit' />
</form>";
?>
The $name and $q are derived from the database using a mysql query. This works fine.
I have used the following javascript code so far:
function RegValidate(Tester)
{
if($('#w1').not(':checked'))
{
alert('Radio not checked');
return false;
}
}
But with this code, I continue to get the error message, and I am not able to move on even though I have selected a radio button.
The while loop produces several sets of radio buttons, as $q, gets the question from the database and posts it on the page along with 3 radio buttons. Each question $q, has the 3 radio buttons in the above, hence the reason for the $name.
How do I validate this form with javascript. NB. The form will only contain radio buttons.
function RegValidate(Tester) {
if ($(":radio[name=w1]:checked").toArray().length == 0) {
alert('nothing selected');
return false;
}
}
FIDDLE
you have an error, your input doesn't have ID or CLASS, so add to all of the input radio class='w1' and try the next code:
if ($(".w1 option:selected").length<1)
alert ('nothing selected');
also take a look to this post: Check if option is selected with jQuery, if not select a default
do these things:
<input type='radio' class='w1' name='w1' value='1'>1<br>
<input type='radio' class='w1' name='w1' value='2'>2<br>
<input type='radio' class='w1' name='w1' value='3'>3<br>
And in js:
Latest edit:
if ( $(':radio[class=w1]').attr('checked') != 'checked' ) {
alert('Radio not checked');
}
I want to refresh the same page and display the entered value in text box on the same page after clicking the link or button.
I have the following code:
<?php
echo '<h3>Fee Payment</h3>';
echo "<form id='myFormId' name='myFormName'>";
echo " <input type='text' name='myTextField'>";
echo "<a href='{$_SERVER['PHP_SELF']}?student_no=myTextField'> Search Student</a>";
if (!(isset($_GET[student_no])))
{
echo "No Student is available.";
}
else
{
$student_no = $_GET['student_no'];
echo "Student NO:".$studen_no;
}
?>
Please guide me how to achieve the goal and whats the error my code.
<?php
echo '<h3>Fee Payment</h3>';
if(isset($_POST['myTextField']))
$value=$_POST['myTextField'];
else
$value='';
echo "<form id='myFormId' name='myFormName' method='post'>";
echo " <input type='text' name='myTextField' value='$value'>";
echo "<a href='{$_SERVER['PHP_SELF']}?student_no=myTextField'> Search Student</a>";
You also need a submit button in the form, and a form close tag.
What you want is AJAX. I am just providing you an example of how you can proceed by using jQuery, but you can use any other library / framework or any other way also. You can check this article also for more usability details.
In the main page:-
<?php
echo '<h3>Fee Payment</h3>';
echo "<form id='myFormId' name='myFormName'>";
echo "<input type='text' name='myTextField' id='myTextField' />";
echo 'Search Student';
echo "</form>";
?>
<script type="text/javascript">
$('#inline_submit_a').click(function(evt){
$.ajax({
type: "GET",
url: "handler.php",
data: {text:$('#myTextField').val()}
});
evt.preventDefault();
return false;
});
</script>
In the "handler.php" page:-
<?php
if (!(isset($_GET[student_no])))
{
echo "No Student is available.";
}
else
{
$student_no = $_GET['student_no'];
echo "Student NO:".$student_no;
}
?>
You can write all the logic related to the database in the "handler.php" page.
Hope it helps.
You're using a link to submit the form, but you should be using a submit button.
<input type="submit" value="Search student" />
You didn't close the <form> tag.
You're using $_GET[student_no] which will make PHP look for a definition of student_no. Since it's a string, express it as one. $_GET['student_no'] is better.
Why can't you submit the form? Do you want to have a link for searching instead of a button?
You could configure the link to submit the form via javascript and change the form action to GET like this:
<?php
echo '<h3>Fee Payment</h3>';
echo "<form id='myFormId' name='myFormName'
action='{$_SERVER['PHP_SELF']}' method='GET'>";
echo " <input type='text' name='student_no'>";
echo "<a href='javscript:document.forms.myFormName.submit()'>
Search Student</a>";
...