LJackson 03-03-2009, 07:11 PM Hi all,
i have a div which includes a button, i want this button to display a message in my div if the validation is correct and submit some data into my database and if the validation is incorrect it displays an error message within the div.
as far as i am aware a form button can only sumit either a get or post which directs to a new page? if i had a button minus the form can i add some custom code to do what i want aove?
cheers
Luke
Old Pedant 03-03-2009, 09:17 PM This is a PHP question. Nothing to do with JavaScript. So I've asked moderator to move it.
Since the form *MUST* submit to the PHP code in order for the captcha value to be tested, you can't do any of this in JavaScript.
LJackson 03-03-2009, 11:25 PM ooops sorry, thanks for asking it to be moved :)
LJackson 03-04-2009, 02:52 PM can someone move it to the php section please :)
thanks
LJackson 03-04-2009, 07:05 PM thanks guys for moving it for me :)
can anyone help me with this please?
cheers
Luke
LJackson 03-05-2009, 03:45 PM anyone!!!!! PLEASE :)
Serihon 03-05-2009, 05:19 PM Hi all,
i have a div which includes a button, i want this button to display a message in my div if the validation is correct and submit some data into my database and if the validation is incorrect it displays an error message within the div.
as far as i am aware a form button can only sumit either a get or post which directs to a new page? if i had a button minus the form can i add some custom code to do what i want aove?
cheers
Luke
As far as I know I believe you will have to use GET and POST with a form to accomplish what you desire. Here is the basic code for something on par with what you are wanting.
<?php
$val = $_GET['val']; //use GET to retrieve val
if(empty($_POST)){
//Check to see if $val is empty.
if(!empty($val)){
$status = 'Information added.';
}else{
$status = 'To add information, fill out the form below. Click the Submit button once.';
}
}else{
$info=$_POST['info']; //use POST to fill $info with information submitted in the form.
$sql="INSERT INTO table "; //table should be changed to the name of your table
$sql.="SET info='$info' ";
if(mysql_query($sql)){
header('Location:thispage.php?val=yes'); //Upon successfully Inserting information into the table takes user to thispage.php?val=yes which passes yes through val to show the user that information was successfully submitted. Change thispage.php to the current pages url.
}else{
$status = 'Unable to add information.'; //Upon unsuccessful insertion of information into the table.
}
}
?>
<div><?php echo $status; ?></div> <!-- displays information based on current status -->
<form enctype="multipart/form-data" action="thispage.php" method="post"> <!-- POST form that returns user to this page -->
<dl>
<dt><label for="info">Insert information.</label></dt>
<dd><input type="text" name="info" id="info" value="" /></dd> <!-- user supplies info to be submitted -->
</dl>
<div>
<input type="submit" name="submit" value="Submit" /> <!-- Upon depression will submit form -->
</div>
</form>
That is the basic code for doing what you were asking using GET, POST, and a form. Not sure it is what you were looking for though.
LJackson 03-05-2009, 06:40 PM Hi mate,
thanks for this, i "did" have something almost working before i wrecked it :(
now i am having quite a few problems with it all :(
i will persevere with it and hopefully get it working :)
Serihon 03-05-2009, 06:49 PM Hi mate,
thanks for this, i "did" have something almost working before i wrecked it :(
now i am having quite a few problems with it all :(
i will persevere with it and hopefully get it working :)
Not a problem. Let me know if you require further assistance.
LJackson 03-05-2009, 06:55 PM will do cheers mate
ohgod 03-05-2009, 07:13 PM what?! why can't he do this in javascript? if he's using ajax this is completely possible.
take your submit button and change type from "submit" to "button". add an onclick event that starts up a validator function.
if the validator sees that the input meets your requirements, it could fire an ajax request which could take the response and generate any output you want based on the results. if the validator says the input fails your requirements it would output the error of your choice.
or if you wanted you could have the submit button remain as is, but stay disabled until the validator says everything is cool. you would use the onkeypress event on your form to monitor the input.
Serihon 03-05-2009, 07:21 PM what?! why can't he do this in javascript? if he's using ajax this is completely possible.
take your submit button and change type from "submit" to "button". add an onclick event that starts up a validator function.
if the validator sees that the input meets your requirements, it could fire an ajax request which could take the response and generate any output you want based on the results. if the validator says the input fails your requirements it would output the error of your choice.
or if you wanted you could have the submit button remain as is, but stay disabled until the validator says everything is cool. you would use the onkeypress event on your form to monitor the input.
Sounds like that would work but I am fairly new to javascript and ajax so wouldn't know for certain. Sounds like you may be a better help to him than I was.
LJackson 03-06-2009, 04:18 PM what?! why can't he do this in javascript? if he's using ajax this is completely possible.
take your submit button and change type from "submit" to "button". add an onclick event that starts up a validator function.
if the validator sees that the input meets your requirements, it could fire an ajax request which could take the response and generate any output you want based on the results. if the validator says the input fails your requirements it would output the error of your choice.
or if you wanted you could have the submit button remain as is, but stay disabled until the validator says everything is cool. you would use the onkeypress event on your form to monitor the input.
hi mate, i know nothing about javascript or ajax so this is going to be difficult for me :), i have changed my button type to button and have added an onclick even but im not sure where to go next?
ideally i would want it to check the image validator to see if it has been inserted correctly and then display a message if it has/hasnt.
here is my form code
<form name="rate" method="post">
<div id="apDiv1">
<table width="294" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="167"><span class="ratingscat_head">Value for money</span></td>
<td width="119"><span class="storeRatings_Individual"><?php print rating_bar('valuetemp',5)?></span></td>
</tr>
<tr>
<td><span class="ratingscat_head">Ease of use</span></td>
<td><span class="storeRatings_Individual"><?php print rating_bar('easeofusetemp',5)?></span></td>
</tr>
<tr>
<td><span class="ratingscat_head">Delivery time</span></td>
<td><span class="storeRatings_Individual"><?php print rating_bar('deliverytemp',5)?></span></td>
</tr>
<tr>
<td><span class="ratingscat_head">P&P costs</span></td>
<td><span class="storeRatings_Individual"><?php print rating_bar('delchargetemp',5)?></span></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /></td>
<td> </td>
</tr>
<tr>
<td colspan="2"><label for="label"><span class="style2">Please Enter Security Code: </span></label></td>
</tr>
<tr>
<td colspan="2"><input id="security_code" name="security_code" type="text" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input type="button" name="button" value="button" onclick=""/></td>
<td><a href="javascript:dropdowncontent.hidediv('subcontent')">Close</a></td>
</tr>
</table>
<P>
</form>
i have some code to check the image validation
if( isset($_POST['submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
$message="Thank you for voting!!!";
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
$message="Sorry, you have provided an invalid security code";
}
} else {}
can it be incorporated into the onclick or another way? does this sound possible?
cheers mate
Luke
LJackson 03-06-2009, 04:24 PM Sounds like that would work but I am fairly new to javascript and ajax so wouldn't know for certain. Sounds like you may be a better help to him than I was.
hi mate, i dont know anything about javascript and ajax so you are better off than me mate :) thanks for your help so far please keep an eye on this thread im sure your wisdom will be useful again at some point
cheers mate
Luke
LJackson 03-06-2009, 05:00 PM hi all,
ok i have learnt a bit of js :)
i have a file which i have called jsfunctions.js and this contains
<script language="javascript" type="text/javascript">
function showAlert() {
alert('Hello World - this is an alert message!');
}
</script>
as a tester
and then i have added this to my button
<input type="Button" name="Button" value="Button" onclick="showAlert();"/>
and this shows the alert when i click on the button :)
so im getting somewhere :)
but im still not sure how to add the img checker to the onclick, can i just copy and paste it into my jsfunctions page?
cheers
Luke
edit
===
i tried adding my php checker code to my js function and nothing :( how do you add php into js? can you do it?
here is my code
function checkimg(){
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
$sql="UPDATE ratings
SET
used_ips = NULL,
total_value = 0,
total_votes = 0
WHERE
id IN ('valuetemp', 'easeofusetemp', 'deliverytemp', 'delchargetemp')";
$query = mysql_query($sql);
alert('Your vote has been counted! Thank you for voting');
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
alert('Sorry, you have provided an invalid security code');
}
}
LJackson 03-07-2009, 10:32 AM Hi all,
i am still very much in need of help with this but i am going away till monday so please dont think i have forgotten about this thread as i havent :)
look forward to reading all your suggestion when i get back :)
cheers
Luke
LJackson 03-09-2009, 04:02 PM ok im back and a little worse for ware lol :)
can anyone help me with this please!!
cheers
Luke
|
|