-1

Was hoping i could get a little help, i am trying to create a sign-up page, that a user can enter a username and password in a textbox and then they can select the type of account they wish to use (customer, business, business employee) from a input type of select. And it will redirect them to the sign up.

eg: user comes to index.php, enters a username and password in my sign-up section, then selects and account type (lets say customer), they click the "sign-up" button and then it will redirect to customer_signup.php where username, password and account type are pre-filled (from the index.php page)

However i am having issues posting what the user has entered, below is my code:

<html>
<head>
<title>Home</title>

<script language="JavaScript">
{
function WinOpen() 
var url=document.redirect.selection.value
document.location.href=url
}

</script>
</head>

<body>
<form name="redirect">

Username: <input type ="textbox" id ="home_username" name = "home_username">
password: <input type ="textbox" id ="home_password" name = "home_password">

<select name="selection">
<option> </option>
<option value="../php_includes/sign_up/customer_signup.php">Customer</option>
<option value="../php_includes/sign_up/business_signup.php">Business</option>
<option value="../php_includes/sign_up/employee_signup.php">Business Employee</option>
<input type=button value="Sign-Up" onClick="WinOpen();">
</form>

</body>
</html>

I want to be able to post home_username, home_password & selection to the next page which will depend on what the user selected. I want to have a button or submit button as i dont want to use the onchange option.

As of right now the code i have does go to the page when selected, however i cant get the text they entered to POST to the next page. I know i have no post as method. and my input type is a button right now (iv been playing around with my code).

was hoping someone might point me in the right direction, am i going about this the wrong way ? should i use button or submit ? iv got javascript to change the page on the select option can i get it to post username and password data?

dertkw
  • 7,798
  • 5
  • 37
  • 45

1 Answers1

0

You need to submit your form.

Change -

<input type=button value="Sign-Up" onClick="WinOpen();">

to -

<input type='submit' value="Sign-Up">

You need some training, follow the tutorial here -

http://www.php.net/manual/en/tutorial.forms.php

and

http://php.net/manual/en/tutorial.php

That should get you started with how to handle form input in PHP. Next you may want to store that data. You can refer to this page for further help -

https://stackoverflow.com/tags/php/info

I'm sorry but I'll have to downvote your question, it lacks research.


EDIT #1 -

Alright, this is what I suggest-

  1. Post the form to a single php page irrespective of the type of user.
  2. Check the type of user on the php page. (Could be using switch like you suggested)
  3. Depending on the type of user, include the necessary php page which takes care of things.

This in my opinion would be a better and simpler way to handle it, rather than doing it on the client side.

The reason your data is currently not going is because when you do a document.location.href=url your form is actually not submitted so none of the data goes through, it's a simple get me the php page request.


EDIT #2 -

I'm not sure if this will work, but let's try -

  1. Add a submit event to your form through JavaScript - Check this answer - How can I listen to the form submit event in javascript?

  2. In the submit JavaScript event, depending on the option selected change the form's action tag - How to use JavaScript to change the form action

  3. Then from the JavaScript event, return true to allow the form to submit.

Let me know if that makes sense.

Community
  • 1
  • 1
Abijeet Patro
  • 2,842
  • 4
  • 37
  • 64
  • sorry i thought my post explained it better, i know how to use form action and set it to a page and display the "posted" details on the next page , when iv set the action to a page but im trying to let the user select the account type and therefore the page could be 1 of 3 pages, im look more towards a function (switch statement maybe) that takes the selected option from the user along with text they have entered and posts it on the page they selected in the account type... i know my code does not look right ( i was playing around with it) trying different ways. – user3577164 Jun 01 '14 at 08:46
  • Thank you for the reply, i was hoping i would not need a "handler" type page (thought there might of been a simpler solution) but that is fine ill have to go down that route! – user3577164 Jun 01 '14 at 08:58
  • @user3577164 - Updated the answer again. – Abijeet Patro Jun 01 '14 at 09:04
  • yea that makes sense and is more towards what i am trying to do, thanks! – user3577164 Jun 01 '14 at 09:24
  • @user3577164 - If it helped, please select this response as an answer. – Abijeet Patro Jun 01 '14 at 10:22