Jump to content
MakeWebGames

Recommended Posts

Posted

I have been struggling with the onclick for a while now. Basically what I would like to accomplish is when the submit button is clicked it brings you to another page and no matter how I set it up it doesn't work. I've included a mock function so that it will help me to understand this better. Thanks in advance for your suggestions/help.

 

function whatever()

{

global $db, $ir, $c, $userid, $h;

$variable=$_POST['variable'];

{

print "<br /><br /><method='post'>Type in whatever.<br /><br />

<input type='text' size='10' maxlength='40' name='variable'>

<input type='submit' name='submit' value='Submit'>

//When they click the submit button it would take them to yadayada.php

</form>";

$db->("INSERT INTO table VALUES('$variable')");

Posted

To summarize

print "<br /><br />

<form action='addpagehere.php' method='post'>Type in whatever.<br /><br />

<input type='text' size='10' maxlength='40' name='variable'>

<input type='submit' name='submit' value='Submit'>

</form>";

Posted

Okay ... this is the full code that I am trying to get to work ... I finally have it so that it posts all the info to the database. Yay!! But I can not get it to redirect to the explore.php page. I've tried the form action under all 4 sections ... no dice. Tried onclick and onsubmit ... still no dice. Tried meta tags ... even tried header redirect and none of them will bring it to the explore page. Any suggestions.

<?php

include "globals.php";

global $db, $ir, $c, $userid, $h;

$name1=$_POST['charname1'];

$type1=$_POST['type1'];

$gender1=$_POST['gender1'];

$alignment1=$_POST['alignment1'];

print "<br /><br />Your first character.<br /><br />";

print "<br /><br /><u><b>Type in your first characters name.</u></b><br /><br />

<form method='post'>

<input type='text' size='10' maxlength='40' name='charname1'>";

 

print "<u><b>Choose your first characters type.</u></b><br />

<form method='post'>

Lycan<input type='radio' name='type1' value='lycan' /><br />

Vampire<input type='radio' name='type1' value='vampire' /><br />

Angel<input type='radio' name='type1' value='angel' /><br />

Demon<input type='radio' name='type1' value='demon' /><br />";

print "<u><b>Choose your first characters gender.</u></b><br />

<form method='post'>

Male<input type='radio' name='gender1' value='male' /><br />

Female<input type='radio' name='gender1' value='female' /><br />";

print "<u><b>Choose your first characters alignment.</u></b><br />

<form method='post'>

Good<input type='radio' name='alignment1' value='good' /><br />

Evil<input type='radio' name='alignment1' value='evil' /><br /><br />

<input type='submit' name='submit' value='Submit your first character.'>

</form><br />";

$db->query("INSERT INTO charone VALUES('".$ir['userid']."','$name1','$type1','$gender1','$alignment1')");

$h->endpage();

?>

Posted

You need to close the <form> tag before you open a new one... And the onclick on a button not a submit will work fine. If you want it on a submit you will need to return false to avoid to do the submit of the form.

Posted

I know that I should close the form tags ... however .. it was the only way that I could get this to work and post all 4 pieces of data to the db. As for getting it to go to the explore.php after it is submitted ... I have tried all the various ways to get it to do so and I have had no luck whatsover.

Posted

Newttster basic html form posting.

form action method

In no way do you ever....ever not close your tags.

<form action='script.php' method='get or post'>

do stuff here so input text

</form>

Now if your form does not work then your doing something wrong.

In your case here then you need to evaluate what your doing

http://php.net/manual/en/function.isset.php

will help you with form posting. why? have a look see if you can figure out why!

  • 3 weeks later...
Posted

* Please ignore any excess <br/>'s, this is a forum bug. Please refresh the page if there is an overload of them

 

<?php
include "globals.php";
global $db, $ir, $c, $userid, $h;
if(isset($_POST['submit']))
{
//the form has been submitted
//i'm only working with the code in the OP
//More security measures need to be taken.

$name1=$_POST['charname1'];

$arrType = array('lycan', 'vampire', 'angel', 'demon');
$type1=$_POST['type1'];

$arrGender = array('male', 'female');
$gender1=$_POST['gender1'];

$arrAlignment = array('good', 'evil');
$alignment1=$_POST['alignment1'];

if(! in_array( $type1, $arrType) ) //if the selection is not in the array
{
  echo "Please choose a type from the list.";
  exit ($h->endpage());
}
if(! in_array( $gender1, $arrGender) )
{
 echo "Please choose a gender from the list.";
 exit ($h->endpage());
}
if(! in_array( $alignment1, $arrAlignment) )
{
  echo "Please choose an alignment from the list.";
  exit( $h->endpage() );
}

echo "Creation was a success!";
$db->query("INSERT INTO `charone` VALUES('".$ir['userid']."','$name1','$type1','$gender1','$alignment1') "); 
}


echo "<h3>Your first character.<h3>
<form action='' method='post'>
<u><b>Type in your first characters name.</u></b>
  <br />
<input type='text' size='10' maxlength='40' name='charname1'>
  <br />
<u><b>Choose your first characters type.</u></b>
  <br />
Lycan<input type='radio' name='type1' value='lycan' />
  <br />
Vampire<input type='radio' name='type1' value='vampire' />
  <br />
Angel<input type='radio' name='type1' value='angel' />
  <br />
Demon<input type='radio' name='type1' value='demon' />
  <br />
<u><b>Choose your first characters gender.</u></b>
  <br />
Male<input type='radio' name='gender1' value='male' />
  <br />
Female<input type='radio' name='gender1' value='female' />
  <br />
<u><b>Choose your first characters alignment.</u></b>
  <br />
Good<input type='radio' name='alignment1' value='good' />
  <br />
Evil<input type='radio' name='alignment1' value='evil' />
  <br />
<input type='submit' name='submit' value='Submit your first character.'>
</form>";
$h->endpage();
?>

 

So, what have i done?

Well, i first added an if() statement to see if the form had been submitted, using isset(). I then did some checks to see if they had selected an option from the list (security measure).

If it was in the list - display a message and update the database

If it wasn't in the list - display a message and exit

Hope it all goes well.

-sniko

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...