Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Undefined variable: maidenname in.

     

Scotty13

4:57 pm on Mar 30, 2012 (gmt 0)



My registration.php form has questions that have to be answered and three that are optional. The three that are optional give me this error in the box when tested in browser.



<br /><b>Notice</b>: Undefined variable: maidenname in <b>/home/*******/********/root/registration.php</b> on line <b>304</b><br />

How do I clear it to make an empty box?

Thanks, Scott

eelixduppy

6:19 pm on Mar 30, 2012 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Your question does not seem to pertain to the error message you are getting from what I can tell.

1) The reason you are getting this error message is because these specific variables were not part of the POSTed data sent to the action form. For these (and really all of them), you should be checking for existance before processing anything, e.g.:


if(isset($_POST['input_name])) {
// do something
} else {
// handle undefined case
}



2) >How do I clear it to make an empty box?
Can you elaborate here? Not sure exactly what you mean.

Scotty13

7:08 pm on Mar 30, 2012 (gmt 0)



Sorry, the error message is in the formField were the maidenname would go.

eelixduppy

7:14 pm on Mar 30, 2012 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Oh so you are doing something like this, then?


<input type="text" name="maidenname" value="<?php echo $_POST['maidenname']; ?>"/>


If that is the case, you need to first check to see if it exists -- if it does you put in the value of the variable, if it doesn't you put in some default value. Here is a simplified version:


if(isset($_POST['maidenname']))
$maidenname = $_POST['maidenname'];
else
$maidenname = "";
echo '<input type="text" name="maidenname" value="' . $maidenname .'"/>';


Let me know if this helps.

incrediBILL

7:21 pm on Mar 30, 2012 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Or use a little function like this for all your fields:

# get parameters passed by POST or GET
# protected against throwing warnings
function get_post($var) {
return isset($_POST[$var]) ? $_POST[$var] : false;
}

Then you can call the function for all form fields, a lot less code to weed through, and anything not filled in won't generate errors:

$maidenname = get_post('maidenname');

If you don't want to be able to check if the value is actually not set, or false, and prefer a blank, change the function to be:

function get_post($var) {
return isset($_POST[$var]) ? $_POST[$var] : "";
}

Scotty13

7:33 pm on Mar 30, 2012 (gmt 0)



THANK YOU! I'll try above comments. This is what I'm working with in the table...

</tr>
<tr>
<td width="136" bgcolor="#FFFFFF"><div align="right">Maiden Name:</div></td>
<td width="360" bgcolor="#FFFFFF"><div align="left">
<input name="maidenname" type="text" class="formFields" id="maidenname" value="<?php print "$maidenname"; ?>" size="32" maxlength="20" />
<span id="nameresponse"><span class="textSize_9px"><span class="greyColor">Alphanumeric Characters Only</span></span></span></div></td>
</tr>
<tr>

Scotty13

7:39 pm on Mar 30, 2012 (gmt 0)



Thanks! FIXED!

Was missing $maidenname = "";

g1smd

7:43 pm on Mar 30, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



With a little bit of CSS you could do away with the div and span code bloat in that example.

eelixduppy

8:14 pm on Mar 30, 2012 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



I mean if you want to get fancy, bill, this is how I would do it ;)


function get_post($var, $default = "") {
return isset($_POST[$var]) ? $_POST[$var] : $default;
}


That way you have one function for every possible need:


get_post('maidenname');
get_post('maidenname', 'Maiden Name');


But I showed it as I did above for its simplicity.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month