1

Hi guys I have a simple form that will allow users to sign up

  <form name="signupform" id="signupform" onsubmit="return false;">
    <div>Username: </div>
    <input id="username" type="text" onblur="checkusername()" onkeyup="restrict('username')" maxlength="16">
    <span id="unamestatus"></span>
    <div>Email Address:</div>
    <input id="email" type="text" onfocus="emptyElement('status')" onkeyup="restrict('email')" maxlength="88">
    <div>Create Password:</div>
    <input id="pass1" type="password" onfocus="emptyElement('status')" maxlength="16">
    <div>Confirm Password:</div>
    <input id="pass2" type="password" onfocus="emptyElement('status')" maxlength="16">
    <div>Unique Company ID:</div>
    <input id="companyID" type="number" onfocus="emptyElement('status')">
    <div>Company Name:</div>
    <input id="compname" type="text" onfocus="emptyElement('status')">
    <button id="signupbtn" onclick="signup()">Create Account</button>
    <span id="status"></span>
  </form>

However, i'm getting a problem in that one of the form parts, the company name is not being commited to a variable, I know this because I check it with the following code in ajax.

if(u == "" || e == "" || p1 == "" || p2 == "" || c == "" || cid == "" || cn == ""){
status.innerHTML = "Fill out all of the form data";

now, the weird thing is I'm sure that I am saving the variables correctly. The form should call the following ajax function.

function signup(){
var u = _("username").value;
var e = _("email").value;
var p1 = _("pass1").value;
var p2 = _("pass2").value;
var cid = _("companyID").value;
var cn = _("compname").value;
var status = _("status");

and then it gets sent with
ajax.send("u="+u+"&e="+e+"&p="+p1+"&c="+c+"&cid="+cid+"&cn"+cn);

and in the php I have it so I assign it to variables in php

// GATHER THE POSTED DATA INTO LOCAL VARIABLES
$u = preg_replace('#[^a-z0-9]#i', '', $_POST['u']);
$e = mysqli_real_escape_string($db_conx, $_POST['e']);
$p = $_POST['p'];
$cid = preg_replace('#[^0-9]#', '', $_POST['cid']);
$cn = preg_replace('#[^a-z0-9.\- ]#', '', $_POST['cn']);
$c = preg_replace('#[^a-z ]#i', '', $_POST['c']);

but it keeps running into that else if, and even when I remove that, no data gets commited to the database for compname ($cn) ONLY, every other variable gets send and stored in the database except for $cn.

Was wondering if I've done something fundamentally wrong here, or its just i've missed something out?

Thanks in advance!

EDIT - changes question to deal with new issue that has arisen.

2
  • Probably just your typo: +"$cn"+cn should be +"&cn"+cn. Although you probably should url encode your values as well. Commented Jan 16, 2014 at 21:17
  • after that is changed this code is getting thrown up status.innerHTML = "Fill out all of the form data"; which is directly after I declare my vars in ajax, where is passes through a check to see if any of the fields are empty. Commented Jan 16, 2014 at 21:20

2 Answers 2

3

The issue is with your AJAX call:

ajax.send("u="+u+"&e="+e+"&p="+p1+"&c="+c+"&cid="+cid+"$cn"+cn);

should be

ajax.send("u="+u+"&e="+e+"&p="+p1+"&c="+c+"&cid="+cid+"&cn="+cn);

Sign up to request clarification or add additional context in comments.

1 Comment

after that gets changed ajax is now telling me "Fill out all the form data" which is related to a check to see if any of the fields are empty.
0

If condition has variable c and your are not setting value for variable c in your signup function.

hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.