didgydont Posted June 4, 2008 Share Posted June 4, 2008 hi all is there a way if both values are good to automaticy post to the next page instead of making a button ? thank you for your time ? <?php if ($fnamecheck=="good" and $lnamecheck=="good"){echo " <p align='center'><form action='displaysearch.php' method='post'> <input type='hidden' name='FirstName' value='$fname'/> <input type='hidden' name='LastName' value='$lname'/> <input type='submit' VALUE='search for $fname $lname'/> </form";} ?> Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/ Share on other sites More sharing options...
prcollin Posted June 4, 2008 Share Posted June 4, 2008 hi all is there a way if both values are good to automaticy post to the next page instead of making a button ? thank you for your time ? <?php if ($fnamecheck=="good" and $lnamecheck=="good"){echo " <p align='center'><form action='displaysearch.php' method='post'> <input type='hidden' name='FirstName' value='$fname'/> <input type='hidden' name='LastName' value='$lname'/> <input type='submit' VALUE='search for $fname $lname'/> </form";} ?> I think that you can do this with javascript not 100% sure about php I will try to direct you to the javascript for this though when i get to work, if you dont find your answer by then Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557292 Share on other sites More sharing options...
didgydont Posted June 4, 2008 Author Share Posted June 4, 2008 thank you im a little scared though cause i know nothing about java and have only been learning php for a couple of months in my spare time. Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557297 Share on other sites More sharing options...
prcollin Posted June 4, 2008 Share Posted June 4, 2008 thank you im a little scared though cause i know nothing about java and have only been learning php for a couple of months in my spare time. Just so I am clear are you just trying to get the values to post to the next page, or are you trying to get them to to post to a database? And if y ou are trying to get them just to post to the next page do you need them to show up in text boxes or just as plain text Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557366 Share on other sites More sharing options...
kev wood Posted June 4, 2008 Share Posted June 4, 2008 i think that can be done with xmlhttprequests this with this i know you are able to interact with the server without the page refreshing. look this up while you wait for the java answer it might be easier for you. Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557370 Share on other sites More sharing options...
didgydont Posted June 4, 2008 Author Share Posted June 4, 2008 thank you im a little scared though cause i know nothing about java and have only been learning php for a couple of months in my spare time. Just so I am clear are you just trying to get the values to post to the next page, or are you trying to get them to to post to a database? And if y ou are trying to get them just to post to the next page do you need them to show up in text boxes or just as plain text just to the next page at the moment if all fields pass it creates a button but i just want it if all fields pass it sends the it post to the next page. Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557377 Share on other sites More sharing options...
didgydont Posted June 4, 2008 Author Share Posted June 4, 2008 i think that can be done with xmlhttprequests this with this i know you are able to interact with the server without the page refreshing. look this up while you wait for the java answer it might be easier for you. thanx will look now Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557378 Share on other sites More sharing options...
ILYAS415 Posted June 4, 2008 Share Posted June 4, 2008 Okay just read. Hmm try something like.... <?php if ($fnamecheck=="good" and $lnamecheck=="good"){ echo " <p align='center'><form action='displaysearch.php' method='post' name='form1'> <input type='hidden' name='FirstName' value='$fname'/> <input type='hidden' name='LastName' value='$lname'/> <input type='submit' VALUE='search for $fname $lname'/> </form>"; echo "<script lanugage='javascript'>document.form1.submit();</script>"; } ?> should work hopefully. I added a name attribute to the form tag and also put some javascript in for your to automatically submit the form. Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557379 Share on other sites More sharing options...
kbh43dz_u Posted June 4, 2008 Share Posted June 4, 2008 thank you im a little scared though cause i know nothing about java and have only been learning php for a couple of months in my spare time. Never ever call javscript "java"! completely different thing No you cant't submit a form with PHP (PHP runs on the server) but with javascript. The way ILYAS415 told you will work! but you probably don't want the form to be submitted right after you loaded the page, so you'll have to tell the function "submit()" WHEN you want to submit, like: <script lanugage='javascript'> function checkForm(){ if(...){ document.form1.submit(); } } window.setInterval(checkForm_ress,100); //check if form has to submit again and again. </script> instead of <script lanugage='javascript'>document.form1.submit();</script> But your problem will be: How do you know if your user has finished his input? (because if it is a search-form you don't know what he enters). (this is why I couldn't fill the "if clause" in my example) Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557398 Share on other sites More sharing options...
ILYAS415 Posted June 4, 2008 Share Posted June 4, 2008 1 second im gunna experiment with my js to see if i can figure out a way... Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557453 Share on other sites More sharing options...
ILYAS415 Posted June 4, 2008 Share Posted June 4, 2008 Okay didnt manage to make the laert work in the below script but it does submit the form IF there are values in the form. The code may actually need some editing. Dont worry js is really easy. Its just like php. <script language='javascript'> function ilyas(value, valuee){ if (empty(value) || empty(valuee)){ alert("No values found"); }else{ document.form1.submit(); } } </script> <form name='form1'> <input type='hidden' name='FirstName' value='<?php echo $fname ?>'/> <input type='hidden' name='LastName' value='<?php echo $lname ?>'/> <a onclick='ilyas(document.form1.FirstName.value, document.form1.LastName.value);'>Submit</a> </form> Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557486 Share on other sites More sharing options...
ILYAS415 Posted June 4, 2008 Share Posted June 4, 2008 Sorry above one doesnt seem to work... <script language='javascript'> function ilyas(value, valuee){ if (value == "" || valuee == ""){ alert("No values found"); }else{ document.form1.submit(); } } </script> <form name='form1'> <input type='text' name='FirstName' /> <input type='text' name='LastName' /> <a onclick='ilyas(document.form1.FirstName.value, document.form1.LastName.value);'>Submit</a> </form> I made the above one using text inputs. Seems to work fine. Change as appropriate. Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557490 Share on other sites More sharing options...
prcollin Posted June 4, 2008 Share Posted June 4, 2008 Why not add in a box at the end that they write y or n for if the information is correct and when that is filled in it automatically is triggered Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557720 Share on other sites More sharing options...
kbh43dz_u Posted June 4, 2008 Share Posted June 4, 2008 Why not add in a box at the end that they write y or n for if the information is correct and when that is filled in it automatically is triggered why no button "send" or "next" -> is there a way if both values are good to automaticy post to the next page instead of making a button ? Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557727 Share on other sites More sharing options...
prcollin Posted June 4, 2008 Share Posted June 4, 2008 Why not add in a box at the end that they write y or n for if the information is correct and when that is filled in it automatically is triggered <script lanugage='javascript'> function ilyas(valuey){ if (valuey==""){ alert("No values found"); }else{ document.form1.submit(); } } </script> <form name='form1'> <input type='text' name='FirstName' /> <input type='text' name='LastName' /> <input type='text' name='YesNo' /> <a onclick='ilyas(document.form1.FirstName.value, document.form1.LastName.value);'>Submit</a> </form> } window.setInterval(checkForm_ress,100); //check if form has to submit again and again. </script> didnt finish code lol got bored but you know what i mean Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-557733 Share on other sites More sharing options...
didgydont Posted June 6, 2008 Author Share Posted June 6, 2008 thanx for the help guys i did want the page to releod before doing the submit because it adds a sql imput then searchs for the name and sorry as im still new to a lot of this coding i did not relise java and javascript were different i think im gonna do the javascript and ajax tutorials at w3schools because all that javascript code looks like jiberish to me. i have included all my code so far so if you guys wants you can see what i was trying to do. very happy now it works great for me anyway thanx again all. <?php include("connect.php"); include("toolbar.php"); putenv('TZ=Australia/Melbourne'); $newuser = "$_POST[newuser]"; echo"<h1>Customer Records</h1> <br /> <table border='0'> <tr> <td> <fieldset> <legend> <h3>Search By:</h3> </legend> <form action='displaysearch.php' method='post'> First Name: <input type='text' name='FirstName' /><br /> Last Name: <input type='text' name='LastName' /><br /> <input type='submit' VALUE='search' /> </form> <form action='idsearch.php' method='post'> Client#: <input type='text' name='Uid' /> <br /> <input type='submit' VALUE='Show Details'/> </form> </fieldset> </td> <td><pre> </pre> </td> <td>"; if ($newuser==1){ $email = "$_POST[Email]"; $fname = "$_POST[FirstName]"; $lname = "$_POST[LastName]"; $land2 = "$_POST[Land]"; $mobile2 = "$_POST[Mobile]"; if(ereg("^[0-9]{8}$", $land2)){ $land = preg_replace("/([0-9]{4})([0-9]{4})/", "03 $1 $2", $land2);} else{$land = preg_replace("/([0-9]{2})([0-9]{4})([0-9]{4})/", "$1 $2 $3", $land2);} $mobile = preg_replace("/([0-9]{4})([0-9]{3})([0-9]{3})/", "$1 $2 $3", $mobile2); $addy = "$_POST[Address]"; //start the form Echo" <fieldset> <legend> <h3>Create A New User</h3> </legend> <form action='index.php' method='post'> <input type='hidden' name='newuser' value='1'/> <table border='0' cellpadding='5' cellspacing='0'>"; //First Name Verification if(eregi("^[A-Za-z' -]{1,50}$", $fname)){ $fnamecheck = "good"; echo "<tr><td>First Name:</td><td> <input type='text' name='FirstName' value='$fname'/></td><td>Okay.</td></tr>";} elseif (empty ($fname)){$fnamecheck = "bad"; Echo "<tr><td>First Name:</td><td> <input type='text' name='FirstName' value='$fname'/></td><td class='redtext'>Empty.</td></tr>";} else {$fnamecheck = "bad"; Echo "<tr><td>First Name:</td><td> <input type='text' name='FirstName' value='$fname'/></td><td class='redtext'>Invalid.</td></tr>";} //Last Name Verification if(eregi("^[A-Za-z' -]{1,50}$", $lname)){$lnamecheck = "good"; echo "<tr><td>Last Name:</td><td><input type='text' name='LastName' value='$lname'/></td><td>Okay.</td></tr>";} elseif (empty ($lname)){$lnamecheck = "bad"; echo "<tr><td>Last Name:</td><td><input type='text' name='LastName' value='$lname'/></td><td class='redtext'>Empty.</td></tr>";} else {$lnamecheck = "bad"; echo "<tr><td>Last Name:</td><td><input type='text' name='LastName' value='$lname'/></td><td class='redtext'>Invalid.</td></tr>";} //Address Verification if (empty ($addy)){$addycheck = "good"; echo "<tr><td>Address:</td><td><input type='text' name='Address' value='$addy'/></td><td>None.</td></tr>";} else {$addycheck = "good"; echo "<tr><td>Address:</td><td><input type='text' name='Address' value='$addy'/></td><td>Okay.</td></tr>";} //Email Verification if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {$emailcheck = "good"; echo "<tr><td>Email:</td><td><input type='text' name='Email' value='$email'/></td><td>Okay.</td></tr>";} elseif (empty ($email)){$emailcheck = "good"; echo "<tr><td>Email:</td><td><input type='text' name='Email' value='$email'/></td><td>None.</td></tr>";} else {$emailcheck = "bad"; echo "<tr><td>Email:</td><td><input type='text' name='Email' value='$email'/></td><td class='redtext'>Invalid.</td></tr>";} //Land Line Verification if(ereg("^[0-9]{2} [0-9]{4} [0-9]{4}$", $land)) {$landcheck = "good"; echo "<tr><td>Land Line:</td><td><input type='text' name='Land' value='$land'/></td><td>Okay.</td></tr>";} elseif (empty ($land)){$landcheck = "good"; echo "<tr><td>Land Line:</td><td><input type='text' name='Land' value='$land'/></td><td>None.</td></tr>";} else {$landcheck = "bad"; echo "<tr><td>Land Line:</td><td><input type='text' name='Land' value='$land'/></td><td class='redtext'>Invalid.</td></tr>";} //Mobile Number Verification if(ereg("^[0-9]{4} [0-9]{3} [0-9]{3}$", $mobile)) {$mobilecheck = "good"; echo "<tr><td>Mobile Nubmer:</td><td><input type='text' name='Mobile' value='$mobile'/></td><td>Okay.</td></tr>";} elseif (empty ($mobile)){$mobilecheck = "good"; echo "<tr><td>Mobile Nubmer:</td><td><input type='text' name='Mobile' value='$mobile'/></td><td>None.</td></tr>";} else {$mobilecheck = "bad"; echo "<tr><td>Mobile Nubmer:</td><td><input type='text' name='Mobile' value='$mobile'/></td><td class='redtext'>Invalid.</td></tr>"; } //End the form Echo "<tr><td></td><td><input type='submit' VALUE='Create User' /></td><td></td></tr> </table> </form>"; if ($fnamecheck=="good" and $lnamecheck=="good" and $addycheck=="good" and $emailcheck=="good" and $landcheck=="good" and $mobilecheck=="good"){echo " <p align='center'><form action='displaysearch.php' method='post' name='form1'> <input type='hidden' name='FirstName' value='$fname'/> <input type='hidden' name='LastName' value='$lname'/> <input type='submit' VALUE='search for $fname $lname'/> </form></p></fieldset>"; $sql="INSERT INTO Clients (FirstName, LastName, Address, Mobile, Landline, Email) VALUES ('$_POST[FirstName]','$_POST[LastName]','$_POST[Address]','$mobile','$land','$_POST[Email]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<script lanugage='javascript'>document.form1.submit();</script>"; } } else {echo "<fieldset> <legend> <h3>Create A New User</h3> </legend> <form action='index.php' method='post'> <input type='hidden' name='newuser' value='1'/> <table border='0' cellpadding='5' cellspacing='0'> <tr><td>First Name:</td><td> <input type='text' name='FirstName'/></td></tr> <tr><td>Last Name:</td><td> <input type='text' name='LastName'/></td></tr> <tr><td>Address:</td><td> <input type='text' name='Address' /></td></tr> <tr><td>Email:</td><td> <input type='text' name='Email' /></td></tr> <tr><td>Land Line:</td><td> <input type='text' name='Land' /></td></tr> <tr><td>Mobile Nubmer:  </td><td> <input type='text' name='Mobile'/></td></tr> <tr><td></td><td><input type='submit' VALUE='Create User' /></td></tr> </table> </form> </fieldset>";} echo"</td> </tr> <tr> <td> <fieldset> <legend> <h3>Delete By The ID#</h3> </legend> <form action='index.php' method='post'> <input type='hidden' name='deluser' value='1'/ > Client#: <input type='text' name='Uid' class='texta' / > <br /> <input type='submit' name=btnG VALUE='Delete User' /> </form> <form action='index.php' method='post'> <input type='hidden' name='deljob' value='1'/ > Job#: <input type='text' name='jobnumber' class='texta' / > <br /> <input type='submit' name=btnG VALUE='Delete Job' /> </form>"; if ($_POST[deljob]==1){mysql_query("DELETE FROM Income WHERE JobID='$_POST[jobnumber]'");echo "<p align='center'>Job has been deleted.</p>";} if ($_POST[deluser]==1){echo "<p align='center'>Client and all their jobs have been deleted.</p>"; mysql_query("DELETE FROM Clients WHERE Uid='$_POST[uid]'"); mysql_query("DELETE FROM Income WHERE ClientID='$_POST[uid]'");} echo"</fieldset> </td> <td><pre> </pre> </td> <td> <fieldset> <legend> <h3>Create A New Job</h3> </legend> <form action='idsearch.php' method='post'> <input type='hidden' name='createjob' value='1' /> <table border='0' cellpadding='5' cellspacing='0'> <tr><td>Client ID:</td><td> <input type='text' name='Uid' /></td></tr> <tr><td>Item Description:</td><td> <input type='text' name='item' /></td></tr> <tr><td>Cost $$$:</td><td> <input type='text' name='cost' /></td></tr> <br /> <tr><td></td><td><input type='submit' VALUE='Create Job' /></td></tr> </table> </form> </fieldset> </td> </tr> </table> <br /> <br /> <br />"; ?> Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-559078 Share on other sites More sharing options...
Wolphie Posted June 6, 2008 Share Posted June 6, 2008 Yes, this is a JavaScript issue. And just to point out, Java is NOT JavaScript. If you're going to be validating the form with PHP, then Ajax is required in order to make the requests to the server. However, you can also validate it with JavaScript too. <form> <input type="text" name="username" id="username" onkeyup="return validate(this.value)"; </form> function validate(element) { switch(element) { case 'wolphie': window.location = 'users/wolphie.php'; break; case 'jimmy': window.location = 'users/jimmy.php'; break; } // Or.. if(element == 'wolphie') alert('Hello ' + element); } Link to comment https://forums.phpfreaks.com/topic/108670-if-okay-automaitcly-do-form/#findComment-559089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.