jQuery manipulating forms - php

For some reason it's not changing the action of the forum. I have some code to change the action of a form when a button is clicked:
function changeForm(event){
alert("Before: "+jQuery("#franchiseform").attr("action"));
jQuery("#franchiseform").attr("action", "franchisepreview.php");
alert("After: "+jQuery("#franchiseform").attr("action"));
jQuery("#franchiseform").submit();
}
The binding:
jQuery("input.preview").bind("click", changeForm);
The form:
<form method="post" enctype="multipart/form-data" action="franchiseinsert.php" class="insert-new" id="franchiseform">
The buttons:
<input type="button" value="Preview" id="preview" name="preview" id="preview" class="preview" /><input type="submit" value="Insert" />

First off, you need to clean up the
<input type="button" value="Preview" id="preview" name="preview" id="preview" class="preview" />
to:
<input type="button" value="Preview" id="preview" name="preview" />
as an input should not have multiple id attributes and you should not use classes and id's with the same name. This could be one reason why you're having problems. Then I used the following code and the action url was actually changing:
<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#preview").bind("click", changeForm);
function changeForm(event){
alert("Before: "+ $("#franchiseform").attr("action"));
$("#franchiseform").attr("action", "franchisepreview.php");
alert("After: "+ $("#franchiseform").attr("action"));
$("#franchiseform").submit();
}
});
</script>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="franchiseinsert.php" class="insert-new" id="franchiseform">
<input type="button" value="Preview" id="preview" name="preview" />
<input type="submit" value="Insert" />
</form>
</body>
</html>

Unless you stripped out too much, it looks like you need to put your "after" call into a function called "changeForm", which is what you are binding to the click event.
otherwise, keep chaining:
jQuery("input.preview").bind("click", function(){
jQuery("#franchiseform").attr("action", "franchisepreview.php"));
jQuery("#franchiseform").submit();
});

It turns out that this is a Firefox / Mac specific bug. It works on other platforms and browsers, but not this specific computer for some reason. It could be an extension conflict or something else, I'll simply use another browser.

Related

need popup window inside a mysql table

i have a simple website which is written by php and mysql code. i have a detect button on my my sql table query page and given below code is writen for this function but my problem is i need a popup window when the detect link is clicked. i have tired to set a code in my created code but i am not able .kindly please help me solve this problem.
<?php $sezione="home_admin"; if(isset($_POST['messaggio']))
$messaggio=$_POST['messaggio'];
include("control_admin..php");
$canc_id=$_GET['canc_id'];
$idcorsocanc=$_POST['idcorsocanc'];
$action=$_REQUEST['action'];?>
<?php
/*echo "permessi".$permessi;
echo "<br>id".$id_nome;*/
if($action=='canc'){?>
<h1>are you sure want to delect the course?</h1>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc1" style="float: left; margin-left:25px;">
<input type="hidden" name="idcorsocanc" value="<?=$canc_id?>">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="Si,cancella" class="puls_invia">
</form>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc2" style="float: left; margin-left:25px;">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="NO" class="puls_invia">
</form>
<?php
}
ok i want to update my question cause i follow one answer and here the code is-
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('#ok').click(function(){
if(confirm('Are you sure ?')){
$('#form').submit();
}else{
return false;
}
});
});
</script>
</head>
<body>
<?php
if(isset($_POST['action'])){
if($_POST['action'] == 'deleted'){
//the form has been sent, do something
}
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="form">
<input type="button" id="ok" name="ok" value="Delete">
<input type="hidden" id="action" name="action" value="deleted">
</form>
<? } ?>
</body>
</html>
but till now my problem is i alreday have link name delect and if i click that link i saw another delete button cause now i use the following code which i just update then if i click there i saw the pop up window but if i click ok that course is not delete cause i guess something is missing.
my actual need is i alreday have delect link and i need something that if i click on that i saw one opoup window.just this is my need.
You need a client-side script to manage this. I'd recommend something in jQuery.
<script type="text/javascript">
$(document).ready(function(){
$(".myButton").click(triggerPopup);
})
function triggerPopup(){
//do popup stuff
}
</script>
an example in more details can be found by googling. something like this http://istockphp.com/jquery/creating-popup-div-with-jquery/
You should do this in javascript. Especially with jquery library
This should look like this :
<?php
include("control_admin.php");
$sezione = "home_admin";
$canc_id = $_GET['canc_id']; //i'm gessing this is the ID to delete ?
?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('#ok').click(function(){
if(confirm('Are you sure ?')){
$('#form').submit();
}else{
return false;
}
});
});
</script>
</head>
<body>
<?
if(isset($_POST['action'])){
if($_POST['action'] == 'deleted'){
$id = $_POST['id'];
$sql = "delete from table_name where column_id = ".$id;
mysql_query($sql);
echo $canc_id . ' has been deleted!';
}
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="form">
<input type="button" id="ok" name="ok" value="Delete">
<input type="hidden" id="action" name="action" value="deleted">
<input type="hidden" id="id" name="id" value="<?=$canc_id?>">
</form>
<? } ?>
</body>
</html>

How to save image after edit in php

I have create a simple image editor with the effects of brightness, contrast, and desaturation etc. I have used for this pixastic functions from www.pixastic.com. The function is working successfully but I don't know how to replace the original image with the adjusted image, with effects. Here is code I have used
<script>
var pixastic_parseonload = true;
</script>
<script src="pixastic.core.js" type="text/javascript"></script>
<script src="actions/desaturate.js" type="text/javascript"></script>
<body>
<form name="form1" action="index.php" enctype="multipart/form-data" method="post">
<p>Image to use:</p>
<img id="scream" class="pixastic <?php echo #$_POST["butn1"];?>" src="Desert.jpg" alt="The Scream" width="220" height="277" name="image1">
<button value="pixastic-desaturate()" name="butn1" >Desaturate</button>
</form>
</bode>
Maybe you need to change this:
<button value="pixastic-desaturate()" name="butn1" >Desaturate</button>
with this:
<input type="button" name="pixastic-desaturate" VALUE="Click to process the image" onClick="pixastic-desaturate();">

Two buttons in a form with different functions

I just wanna ask how can I make a form with two buttons that do different functions? Like for example: I have this table with checkboxes and when a checkbox was checked and a certain button was clicked, the button will perform its assigned task.
Button1 can add, button2 can delete.
Can you help me again, please? I'm kind of new at this and I really want to know. Thank you!
This is more of a JavaScript question than PHP.
You'll need to add an onclick to your buttons:
<input type="button" onclick="functionA();" value="button a" />
<input type="button" onclick="functionB();" value="button b" />
Then create these functions in JavaScript:
function functionA()
{
// do stuff
alert("add");
}
function functionB()
{
// do stuff
alert("delete");
}
Here's a basic example of where you can stick your JavaScript etc:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript">
function functionA()
{
// do stuff
alert("add");
}
function functionB()
{
// do stuff
alert("delete");
}
</script>
</head>
<body>
<input type="button" onclick="functionA();" value="button a" />
<input type="button" onclick="functionB();" value="button b" />
</body>
</html>
If you are looking at a server side solution, you can have two submit buttons in the form with different name attributes and then check the $_GET['buttonName'] or $_POST['buttonName'] variables depending on your form submission method.
For example:
<form action="action.php" method="post">
<input type="text"....blah blah />
....
<input type="submit" name="add" value="Add" />
<input type="submit" name="delete" value="Delete" />
</form>

error after submit a form

i have a php like this:
<?php
......
?>
<html>
<head></head>
<body>
<div id="content">
<form id="myform" name="myform">
<?php include_once("ronny.php"); ?>
.....
<input type="button" value="Save" id="Save" name="Save" onclick="if(check123()==true){document.myform.submit()}" />
</div>
</form>
...
Now, in this case after i click on save i have an error document.myform.submit is not a function in firebug and in IE the error is Object doesn't support this property or method.
If i delete the <?php include_once("ronny.php"); ?> everything is ok.
ronny.php is like that:
<?php
if(......)){
?>
<div></div>
<div></div>
<SCRIPT LANGUAGE="JavaScript">
....
</SCRIPT>
<?php } ?>
If i put the include in the php at the top it's ok as well.
thank you!
document.myform.submit()
myform should be the name of form.
What is check123()? Function?
If you want to use the document.myform notation, you'll have to add a name= attribute to the form tag:
<form name="myform">
...
</form>
or if you have to stick with the id version, then use this in Javascript:
document.getElementById('myform').submit();
Beyond that, what's in the ronny.php function? If taking it out makes the form work, then obviously something in ronny.php is messing with your HTML and/or Javascript and "breaking" things.
I would do :
<input type="button" value="Save" id="Save" name="Save" onclick="check123();this.form.submit();" />

Javascript autosubmit form

I have a form that I need to submit automatically... (the fields are already filled and its complicated to explain why but it IS necessary to do it this way)..
I know how to autosubmit the form using Javascript but the only problem I have is that there is more than 1 submit button.. and I need 1 in particular to be submitted...
thanks in advance
EDIT2(source):
<I put the javascript in the head... />
<FORM ACTION="PDF.php" name="form" METHOD="post">
<A whole bunch of inputs />
<INPUT TYPE="submit" name="form-save" VALUE="Save Changes" >
<INPUT TYPE="submit" name="form-submit" VALUE="Submit" >
<input type="submit" name="print" id="print" value="Download PDF" />
</form>
instead of going for a click event on a submit button, you can call submit of a form object from javascript.
Example :
<head>
<title>Auto Submit Form</title>
<script type="text/javascript">
window.onload = function () {
var form = document.getElementById("PDFGenerationForm");
form.submit();
};
function OnFormSubmit() {
alert("Submitting form.");
}
</script>
<body>
<form id="PDFGenerationForm" action="" method="post" onsubmit="OnFormSubmit">
<!--Any input tags go in here-->
</form>
This editor won't let me paste the whole HTML in here. So, it is in fragments.
$("#yourbuttonid").click();
EDIT:
<form>
...
<input type="submit" id="myFirstsubmit" />
<input type="submit" id="mysubmit" />
</form>
<script type="text/javascript">
$(document).ready(function(){$("#mysubmit").click();});
</script>
If you really want to click a specific button, add this script to the end of your page:
<script type="text/javascript">
// press the button
var myButton = document.getElementById("idOfTheButtonToClick");
myButton.click();
</script>
This assumes your button has an ID.
1) Here is a working auto-submit method: when page is loaded, the form will be immediately autosubmited (the values can be set with php variables too.)
<form action="page.php" name="FORM_NAME" method="post">
<input type="text" name="example1" value="YOUR_VALUE" />
<input type="submit" />
</form>
<SCRIPT TYPE="text/JavaScript">document.forms["FORM_NAME"].submit();</SCRIPT>
or use for any form on that page:
document.forms[0].submit();
2) you can use button-click (called after 1 second):
<SCRIPT TYPE="text/JavaScript">setInterval(function () {document.getElementById("myButtonId").click();}, 1000);</SCRIPT>

Categories