ok, so i have a javascript driven survey page. the nature of the survey is such that if the user answers certain questions, then other questions are automatically disabled (e.g. if you answer question A, then Question D is disabled, but if you answer Question B, then Question D is enabled). So obviously, disabled form fields are not going to get submitted.
Anyway, what i need to know is if there is an efficient way in PHP to assign the submitted form fields to variables in my script without testing for their existence first?
right now i have
if ($_POST['question1'])
{
$q1 = $_POST['question1'];
}
if ($_POST['question2'])
{
$q2 = $_POST['question2']);
}
etc.. only problem is, i have about 60 questions, of which anywhere between 20-30 of them will not be submitted. Writing all those if statements for each possible answer just seems really tedious to me.
I know in ASP/VBScript, a variable assigned to an empty POST value automatically gets an empty string as it's value, but in PHP that would generate an error.
so, what i'm asking is if there is a way in PHP for me to simply say:
$q1 = $_POST['question1'];
and have $q1 automatically get an empty string (or NULL value) if question1 was not in the submitted $_POST variables?
Anyway, what i need to know is if there is an efficient way in PHP to assign the submitted form fields to variables in my script without testing for their existence first?
right now i have
if ($_POST['question1'])
{
$q1 = $_POST['question1'];
}
if ($_POST['question2'])
{
$q2 = $_POST['question2']);
}
etc.. only problem is, i have about 60 questions, of which anywhere between 20-30 of them will not be submitted. Writing all those if statements for each possible answer just seems really tedious to me.
I know in ASP/VBScript, a variable assigned to an empty POST value automatically gets an empty string as it's value, but in PHP that would generate an error.
so, what i'm asking is if there is a way in PHP for me to simply say:
$q1 = $_POST['question1'];
and have $q1 automatically get an empty string (or NULL value) if question1 was not in the submitted $_POST variables?