Menu
1.
[code]
if(!$current_value_matched == ‘TRUE’)
2.
[code]
if($current_value_matched !== ‘TRUE’)
3.
[code]
if(!$current_value_matched = ‘TRUE’)
4.
[code]
if($current_value_matched != ‘TRUE’)
I tried all of them and none of them give the results I want.
I reckon number 4 is correct.
=
'TRUE'
<i>
</i>Notice: Undefined offset: 7 in C:xampphtdocstestrecord_add.php on line 133
Notice: Undefined offset: 7 in C:xampphtdocstestrecord_add.php on line 135
Notice: Undefined offset: 8 in C:xampphtdocstestrecord_add.php on line 133
Notice: Undefined offset: 8 in C:xampphtdocstestrecord_add.php on line 135
Notice: Undefined offset: 9 in C:xampphtdocstestrecord_add.php on line 133
Notice: Undefined offset: 9 in C:xampphtdocstestrecord_add.php on line 135
Notice: Undefined offset: 10 in C:xampphtdocstestrecord_add.php on line 133
<i>
</i>while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i>
</i>foreach($form_questions_labels as $value)
{
$required_current_count_match = 'False';
$textbox_current_count_match = 'False';
$textarea_current_count_match = 'False';
$radio_button_current_count_match = 'False';
$dropdown_current_count_match = 'False';
<i> </i> $current_value_matched = 'FALSE';
<i> </i>
<i> </i> //Check if current Question is a * REQUIRED Question or not.
<i> </i> //There are 7 required questions: $form_questions_required_labels = array().
<i> </i> $required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = 'False';
<i> </i> while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_required_labels[$required_current_count]")
<i> </i> {
<i> </i> $current_required_label_number = $required_current_count;
<i> </i> $required_current_count_match = 'TRUE';
<i> </i> $required_current_count = $required_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i>
</i>$required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = 'False';
while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i>
</i><?php
/*
This file/webpage allows the user to both create New Records and Edit Existing Records.
*/
//Connect to the database.
include("conn.php");
//'USER' Form.
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');
//TEXT BOX LABELS.
$form_questions_textboxes_labels = array('First Name','Middle Name','Surname','Profession','Work Title','Personal Email','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State');
//TEXT AREA LABELS.
$form_questions_textareas_labels = array('About Me');
//RADIO BUTTON LABELS.
$form_questions_radio_buttons_labels = array('Gender','Marital Status','Working Status');
//DROPDOWN LABELS.
$form_questions_dropdowns_labels = array('Age Range','Education','Home Country');
//RADIO BUTTONES AND THEIR OPTIONS
//'Gender' Options
$form_radio_button_number_[0] = array('Male','Female');
//'Marital Status' Options
$form_radio_button_number_[1] = array('Single','Married');
//'Working Status' Options
$form_radio_button_number_[2] = array('Working','Not Working');
//DROPDOWNS AND THEIR OPTIONS
//'Age Range' Options
$form_dropdown_number_[0] = array('Select here','Under 16','16-20','21-25','26-30','31-35','36-40','41-45','46-50','51-55','56-60','61-65','66-70','71-75','76-80','81-85','86-90','91-95','96-100','100+');
//'Education' Options
$form_dropdown_number_[1] = array('Select here','No Education','Primary School','Secondary School','High School','College','University');
//'Home Country' Options
$form_dropdown_number_[2] = array('Select here','Australia','Canada','New Zealand','USA','UK');
//Creates the New/Edit Record Webform.
//Since this webform is used multiple times in this file, best to make a function that is easily reusable to call the webform.
function renderForm($first_name = '', $middle_name = '', $surname = '', $gender = '', $age_range = '', $education = '', $marital_status = '', $working_status = '', $profession = '', $work_title = '', $personal_email = '', $about_me = '', $home_area = '', $home_town = '', $home_neighbourhood = '', $home_council = '', $home_borough = '', $home_city = '', $home_county = '', $home_district = '', $home_region = '', $home_state = '', $home_country = '', $error = '', $id = '')
{
//'USER' Form.
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');
<i> </i>//TEXT BOX LABELS.
<i> </i>$form_questions_textboxes_labels = array('First Name','Middle Name','Surname','Profession','Work Title','Personal Email','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State');
<i> </i>//TEXT AREA LABELS.
<i> </i>$form_questions_textareas_labels = array('About Me');
<i> </i>//RADIO BUTTON LABELS.
<i> </i>$form_questions_radio_buttons_labels = array('Gender','Marital Status','Working Status');
<i> </i>//DROPDOWN LABELS.
<i> </i>$form_questions_dropdowns_labels = array('Age Range','Education','Home Country');
<i> </i>//RADIO BUTTONES AND THEIR OPTIONS
<i> </i>//'Gender' Options
<i> </i>$form_radio_button_number_[0] = array('Male','Female');
<i> </i>//'Marital Status' Options
<i> </i>$form_radio_button_number_[1] = array('Single','Married');
<i> </i>//'Working Status' Options
<i> </i>$form_radio_button_number_[2] = array('Working','Not Working');
<i> </i>
<i> </i>//DROPDOWNS AND THEIR OPTIONS
<i> </i>//'Age Range' Options
<i> </i>$form_dropdown_number_[0] = array('Select here','Under 16','16-20','21-25','26-30','31-35','36-40','41-45','46-50','51-55','56-60','61-65','66-70','71-75','76-80','81-85','86-90','91-95','96-100','100+');
<i> </i>//'Education' Options
<i> </i>$form_dropdown_number_[1] = array('Select here','No Education','Primary School','Secondary School','High School','College','University');
<i> </i>//'Home Country' Options
<i> </i>$form_dropdown_number_[2] = array('Select here','Australia','Canada','New Zealand','USA','UK');
<i> </i>?>
<i> </i><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<i> </i><html>
<i> </i><head>
<i> </i><title>
<i> </i><?php
<i> </i>if ($id != '') //This $id is 'post id' & 'user id'.
<i> </i>{
<i> </i> echo "Edit Existing Personal Profile:";
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo "Add New Personal Profile:";
<i> </i>}
<i> </i>?>
<i> </i></title>
<i> </i><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<i> </i></head>
<i> </i><body>
<i> </i><?php
<i> </i>if ($id != '') //This $id is 'post id' & 'user id'.
<i> </i>{
<i> </i> echo "<h2>Edit Existing Personal Profile:</h2>";
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo "<h2>Add New Personal Profile:</h2>";
<i> </i>}
<i> </i>
<i> </i>if ($error != '')
<i> </i>{
<i> </i> echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error. "</div>";
<i> </i>}
<i> </i>?>
<i> </i><div class="container">
<i> </i><form action="" method="post">
<i> </i><?php
<i> </i>if($id != '')
<i> </i>{
<i> </i> ?>
<i> </i> <input type="hidden" name="id" value="<?php echo $id; //This $id is 'post id' & 'user id'.?>" />
<i> </i> <p>ID: <?php echo $id; //This $id is 'post id' & 'user id'. ?></p>
<i> </i> <?php
<i> </i>}
<i> </i>
<i> </i>foreach($form_questions_labels as $value)
<i> </i>{
<i> </i> $required_current_count_match = 'False';
<i> </i> $textbox_current_count_match = 'False';
<i> </i> $textarea_current_count_match = 'False';
<i> </i> $radio_button_current_count_match = 'False';
<i> </i> $dropdown_current_count_match = 'False';
<i> </i>
<i> </i> $current_value_matched = 'FALSE';
<i> </i>
<i> </i> //Check if current Question is a * REQUIRED Question or not.
<i> </i> //There are 7 required questions: $form_questions_required_labels = array().
<i> </i> $required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = 'False';
<i> </i> while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_required_labels[$required_current_count]")
<i> </i> {
<i> </i> $current_required_label_number = $required_current_count;
<i> </i> $required_current_count_match = 'TRUE';
<i> </i> $required_current_count = $required_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != 'TRUE')
<i> </i> {
<i> </i> //Check if current Question's input type is a TextBox or not.
<i> </i> //There are 16 TextBox questions: $form_questions_textboxes_labels = array().
<i> </i> $textbox_current_count = '0'; $textbox_count_end = '15'; $textbox_current_count_match = 'False';
<i> </i> while($value != $form_questions_textboxes_labels[$required_current_count] || $textbox_current_count != $textbox_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_textboxes_labels[$textbox_current_count]")
<i> </i> {
<i> </i> $current_textbox_label_number = $textbox_current_count;
<i> </i> $textbox_current_count_match = 'True';
<i> </i> $textbox_current_count = $textbox_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $textbox_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != 'TRUE')
<i> </i> {
<i> </i> //Check if current Question's input type is a TextArea or not.
<i> </i> //There is 1 TextArea question: $form_questions_textareas_labels = array().
<i> </i> $textarea_current_count = '0'; $textarea_count_end = '0'; $textarea_current_count_match = 'False';
<i> </i> while($value != $form_questions_textareas_labels[$required_current_count] || $textarea_current_count != $textarea_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_textareas_labels[$textarea_current_count]")
<i> </i> {
<i> </i> $current_textarea_label_number = $textarea_current_count;
<i> </i> $textarea_current_count_match = 'True';
<i> </i> $textarea_current_count = $textarea_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $textarea_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != 'TRUE')
<i> </i> {
<i> </i> //Check if current Question's input type is a RadioButton or not.
<i> </i> //There are 3 RadioButton questions: $form_questions_radio_buttons_labels = array().
<i> </i> $radio_button_current_count = '0'; $radio_button_count_end = '2'; $radio_button_current_count_match = 'False';
<i> </i> while($value != $form_questions_radiobuttons_labels[$required_current_count] || $radio_button_current_count != $radio_button_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_radio_buttons_labels[$radio_button_current_count]")
<i> </i> {
<i> </i> $current_radio_button_number = $radio_button_current_count;
<i> </i> $radio_button_current_count_match = 'True';
<i> </i> $radio_button_current_count = $radio_button_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $radio_button_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != 'TRUE')
<i> </i> {
<i> </i> //Check if current Question's input type is a DropDown or not.
<i> </i> //There are 3 DropDown questions: $form_questions_dropdowns_labels = array().
<i> </i> $dropdown_current_count = '0'; $dropdown_count_end = '2'; $dropdown_current_count_match = 'False';
<i> </i> while($value != $form_questions_dropdowns_labels[$required_current_count] || $dropdown_current_count != $dropdown_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_dropdowns_labels[$dropdown_current_count]")
<i> </i> {
<i> </i> $current_drop_down_number = $dropdown_current_count;
<i> </i> $dropdown_current_count_match = 'True';
<i> </i> $dropdown_current_count = $dropdown_count_end;
<i> </i>
<i> </i> $current_value_matched = 'TRUE';
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $dropdown_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i>
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a TextBox.
<i> </i> if($required_current_count_match == 'False' && $textbox_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: </b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <input type="text" name="<?php echo $value_2;?>" value="<?php echo ${$value_2}; ?>"/>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a TextArea.
<i> </i> elseif($required_current_count_match == 'False' && $textarea_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: </b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <textarea name="<?php echo $value_2;?>" rows="10" cols="30">
<i> </i> <?php
<i> </i> if ($id != '') //This $id is 'post id' & 'user id'.
<i> </i> {
<i> </i> echo ${$value_2};
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> echo "Write about yourself here.";
<i> </i> }
<i> </i> ?>
<i> </i> </textarea>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a RadioButton.
<i> </i> elseif($required_current_count_match == 'False' && $radio_button_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: </b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <?php
<i> </i> foreach($form_radio_button_number_[$current_radio_button_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' && $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even <?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?>
<i> </i> <input type="radio" name="<?php echo $value_2;?>" value="<?php echo ${$value_2};?>" checked><?php echo ${$value_2};?>
<i> </i> <?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?>
<i> </i> <input type="radio" name="<?php echo $value_2;?>" value="<?php echo $value_3;?>"><?php echo $value_3;?>
<i> </i> <?php
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a DropDown.
<i> </i> elseif($required_current_count_match == 'False' && $dropdown_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: </b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <select id="<?php echo $value_2;?>" name="<?php echo $value_2;?>">
<i> </i> <?php
<i> </i> foreach($form_dropdown_number_[$current_drop_down_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' && $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even <?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?>
<i> </i> <option value="<?php echo ${$value_2};?>" selected><?php echo ${$value_2};?></option>
<i> </i> <?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?>
<i> </i> <option value="<?php echo $value_3;?>"><?php echo $value_3;?></option>
<i> </i> <?php
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i> </select>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a TextBox.
<i> </i> if($required_current_count_match == 'True' && $textbox_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: *</b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <input type="text" name="<?php echo $value_2;?>" value="<?php echo ${$value_2}; ?>"/>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a TextArea.
<i> </i> elseif($required_current_count_match == 'True' && $textarea_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: *</b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <textarea name="<?php echo $value_2;?>" rows="10" cols="30">
<i> </i> <?php
<i> </i> if ($id != '') //This $id is 'post id' & 'user id'.
<i> </i> {
<i> </i> echo ${$value_2};
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> echo "Write about yourself here.";
<i> </i> }
<i> </i> ?>
<i> </i> </textarea>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a RadioButton.
<i> </i> elseif($required_current_count_match == 'True' && $radio_button_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: *</b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <?php
<i> </i> foreach($form_radio_button_number_[$current_radio_button_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' && $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even <?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?>
<i> </i> <input type="radio" name="<?php echo $value_2;?>" value="<?php echo ${$value_2};?>" checked><?php echo ${$value_2};?>
<i> </i> <?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?>
<i> </i> <input type="radio" name="<?php echo $value_2;?>" value="<?php echo $value_3;?>"><?php echo $value_3;?>
<i> </i> <?php
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a DropDown.
<i> </i> elseif($required_current_count_match == 'True' && $dropdown_current_count_match == 'True')
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: *</b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <select id="<?php echo $value_2;?>" name="<?php echo $value_2;?>">
<i> </i> <?php
<i> </i> foreach($form_dropdown_number_[$current_drop_down_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' && $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even <?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?>
<i> </i> <option value="<?php echo ${$value_2};?>" selected><?php echo ${$value_2};?></option>
<i> </i> <?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?>
<i> </i> <option value="<?php echo $value_3;?>"><?php echo $value_3;?></option>
<i> </i> <?php
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i> </select>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i>}
<i> </i>?>
<i> </i><input type="submit" name="submit" value="Submit" />
<i> </i></form>
<i> </i></div>
<i> </i></body>
<i> </i></html>
<?php
}
>@developer_web#1611814 Ok. So, how to turn the 'TRUE' into 'boolean' ?
<i>
</i>if($something == true) {
>@developer_web#1611815 I do not understand where "offset 7" comes into play
<i>
</i>while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
$required_current_count
$form_questions_required_labels
isset()
>@NogDog#1611816 Just remove the quotes.
<i>
</i>11:18 $ /usr/bin/php -a
Interactive shell
php > $foo = TRUE;
php > $bar = true;
php > if($foo === $bar) {
php { echo "samen";
php { } else {
php { echo "differentn";
php { }
same
php > $foo = 'TRUE';
php > $bar = 'True';
php > if($foo == $bar) {
php { echo "samen";
php { } else {
php { echo "differentn";
php { }
different
php >
true
false
==
!=
===
!==
<i>
</i>if($some_boolean_value) { ... }
// ...is the same as...
if($some_boolean_value == true) { ... }
// and
if( ! $some_boolean_value) { ... }
// ...is the same as...
if($some_boolean_value == false) { ... }
<i>
</i>//Check if current Question is a * REQUIRED Question or not.
//There are 7 required questions: $form_questions_required_labels = array().
$required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = false;
while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i>
</i><?php
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');
foreach($form_questions_labels as $value)
{
$required_current_count_match = false;
$textbox_current_count_match = false;
$textarea_current_count_match = false;
$radio_button_current_count_match = false;
$dropdown_current_count_match = false;
<i> </i> $current_value_matched = false;
<i> </i>
<i> </i> //Check if current Question is a * REQUIRED Question or not.
<i> </i> //There are 7 required questions: $form_questions_required_labels = array().
<i> </i> $required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = false;
<i> </i> while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_required_labels[$required_current_count]")
<i> </i> {
<i> </i> $current_required_label_number = $required_current_count;
<i> </i> $required_current_count_match = true;
<i> </i> $required_current_count = $required_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i>
<i>
</i>if(isset($form_questions_required_labels[$required_current_count]))
{
while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
{
if($value == "$form_questions_required_labels[$required_current_count]")
{
$current_required_label_number = $required_current_count;
$required_current_count_match = true;
$required_current_count = $required_count_end;
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i>
<i>
</i>//Check if current Question is a * REQUIRED Question or not.
//There are 7 required questions: $form_questions_required_labels = array().
$required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = false;
while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
{
if(isset($form_questions_required_labels[$required_current_count]))
{
if($value == "$form_questions_required_labels[$required_current_count]")
{
$current_required_label_number = $required_current_count;
$required_current_count_match = true;
$required_current_count = $required_count_end;
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i>
<i>
</i>$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');
<i>
</i>//Connect to the database.
include("conn.php");
//'USER' Form.
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');
//TEXT BOX LABELS.
$form_questions_textboxes_labels = array('First Name','Middle Name','Surname','Profession','Work Title','Personal Email','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State');
//TEXT AREA LABELS.
$form_questions_textareas_labels = array('About Me');
//RADIO BUTTON LABELS.
$form_questions_radio_buttons_labels = array('Gender','Marital Status','Working Status');
//DROPDOWN LABELS.
$form_questions_dropdowns_labels = array('Age Range','Education','Home Country');
//RADIO BUTTONES AND THEIR OPTIONS
//'Gender' Options
$form_radio_button_number_[0] = array('Male','Female');
//'Marital Status' Options
$form_radio_button_number_[1] = array('Single','Married');
//'Working Status' Options
$form_radio_button_number_[2] = array('Working','Not Working');
//DROPDOWNS AND THEIR OPTIONS
//'Age Range' Options
$form_dropdown_number_[0] = array('Select here','Under 16','16-20','21-25','26-30','31-35','36-40','41-45','46-50','51-55','56-60','61-65','66-70','71-75','76-80','81-85','86-90','91-95','96-100','100+');
//'Education' Options
$form_dropdown_number_[1] = array('Select here','No Education','Primary School','Secondary School','High School','College','University');
//'Home Country' Options
$form_dropdown_number_[2] = array('Select here','Australia','Canada','New Zealand','USA','UK');
//Creates the New/Edit Record Webform.
//Since this webform is used multiple times in this file, best to make a function that is easily reusable to call the webform.
function renderForm($first_name = '', $middle_name = '', $surname = '', $gender = '', $age_range = '', $education = '', $marital_status = '', $working_status = '', $profession = '', $work_title = '', $personal_email = '', $about_me = '', $home_area = '', $home_town = '', $home_neighbourhood = '', $home_council = '', $home_borough = '', $home_city = '', $home_county = '', $home_district = '', $home_region = '', $home_state = '', $home_country = '', $error = '', $id = '')
{
//'USER' Form.
$form_questions_labels = array('First Name','Middle Name','Surname','Gender','Age Range','Education','Marital Status','Working Status','Profession','Work Title','Personal Email','About Me','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State','Home Country');
$form_questions_required_labels = array('First Name','Surname','Gender','Age Range','Personal Email','About Me','Home Country');
<i> </i>//TEXT BOX LABELS.
<i> </i>$form_questions_textboxes_labels = array('First Name','Middle Name','Surname','Profession','Work Title','Personal Email','Home Area','Home Town','Home Neighbourhood','Home Council','Home Borough','Home City','Home County','Home District','Home Region','Home State');
<i> </i>//TEXT AREA LABELS.
<i> </i>$form_questions_textareas_labels = array('About Me');
<i> </i>//RADIO BUTTON LABELS.
<i> </i>$form_questions_radio_buttons_labels = array('Gender','Marital Status','Working Status');
<i> </i>//DROPDOWN LABELS.
<i> </i>$form_questions_dropdowns_labels = array('Age Range','Education','Home Country');
<i> </i>//RADIO BUTTONES AND THEIR OPTIONS
<i> </i>//'Gender' Options
<i> </i>$form_radio_button_number_[0] = array('Male','Female');
<i> </i>//'Marital Status' Options
<i> </i>$form_radio_button_number_[1] = array('Single','Married');
<i> </i>//'Working Status' Options
<i> </i>$form_radio_button_number_[2] = array('Working','Not Working');
<i> </i>
<i> </i>//DROPDOWNS AND THEIR OPTIONS
<i> </i>//'Age Range' Options
<i> </i>$form_dropdown_number_[0] = array('Select here','Under 16','16-20','21-25','26-30','31-35','36-40','41-45','46-50','51-55','56-60','61-65','66-70','71-75','76-80','81-85','86-90','91-95','96-100','100+');
<i> </i>//'Education' Options
<i> </i>$form_dropdown_number_[1] = array('Select here','No Education','Primary School','Secondary School','High School','College','University');
<i> </i>//'Home Country' Options
<i> </i>$form_dropdown_number_[2] = array('Select here','Australia','Canada','New Zealand','USA','UK');
<i> </i>?>
<i> </i><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<i> </i><html>
<i> </i><head>
<i> </i><title>
<i> </i><?php
<i> </i>if ($id != '') //This $id is 'post id' & 'user id'.
<i> </i>{
<i> </i> echo "Edit Existing Personal Profile:";
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo "Add New Personal Profile:";
<i> </i>}
<i> </i>?>
<i> </i></title>
<i> </i><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<i> </i></head>
<i> </i><body>
<i> </i><?php
<i> </i>if ($id != '') //This $id is 'post id' & 'user id'.
<i> </i>{
<i> </i> echo "<h2>Edit Existing Personal Profile:</h2>";
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo "<h2>Add New Personal Profile:</h2>";
<i> </i>}
<i> </i>
<i> </i>if ($error != '')
<i> </i>{
<i> </i> echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error. "</div>";
<i> </i>}
<i> </i>?>
<i> </i><div class="container">
<i> </i><form action="" method="post">
<i> </i><?php
<i> </i>if($id != '')
<i> </i>{
<i> </i> ?>
<i> </i> <input type="hidden" name="id" value="<?php echo $id; //This $id is 'post id' & 'user id'.?>" />
<i> </i> <p>ID: <?php echo $id; //This $id is 'post id' & 'user id'. ?></p>
<i> </i> <?php
<i> </i>}
<i> </i>
<i> </i>foreach($form_questions_labels as $value)
<i> </i>{
<i> </i> $required_current_count_match = false;
<i> </i> $textbox_current_count_match = false;
<i> </i> $textarea_current_count_match = false;
<i> </i> $radio_button_current_count_match = false;
<i> </i> $dropdown_current_count_match = false;
<i> </i>
<i> </i> $current_value_matched = false;
<i> </i>
<i> </i> //Check if current Question is a * REQUIRED Question or not.
<i> </i> //There are 7 required questions: $form_questions_required_labels = array().
<i> </i> $required_current_count = '0'; $required_count_end = '6'; $required_current_count_match = false;
<i> </i> if(isset($form_questions_required_labels[$required_current_count]) && $required_count_end)
<i> </i> {
<i> </i> while($value != $form_questions_required_labels[$required_current_count] || $required_current_count != $required_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_required_labels[$required_current_count]")
<i> </i> {
<i> </i> $current_required_label_number = $required_current_count;
<i> </i> $next_required_label_number = $required_current_count++;
<i> </i> $required_current_count_match = true;
<i> </i> $required_current_count = $required_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $required_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != true)
<i> </i> {
<i> </i> //Check if current Question's input type is a TextBox or not.
<i> </i> //There are 16 TextBox questions: $form_questions_textboxes_labels = array().
<i> </i> $textbox_current_count = '0'; $textbox_count_end = '15'; $textbox_current_count_match = false;
<i> </i> while($value != $form_questions_textboxes_labels[$textbox_current_count] || $textbox_current_count != $textbox_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_textboxes_labels[$textbox_current_count]")
<i> </i> {
<i> </i> $current_textbox_label_number = $textbox_current_count;
<i> </i> $textbox_current_count_match = true;
<i> </i> $textbox_current_count = $textbox_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $textbox_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != true)
<i> </i> {
<i> </i> //Check if current Question's input type is a TextArea or not.
<i> </i> //There is 1 TextArea question: $form_questions_textareas_labels = array().
<i> </i> $textarea_current_count = '0'; $textarea_count_end = '0'; $textarea_current_count_match = false;
<i> </i> while($value != $form_questions_textareas_labels[$textarea_current_count] || $textarea_current_count != $textarea_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_textareas_labels[$textarea_current_count]")
<i> </i> {
<i> </i> $current_textarea_label_number = $textarea_current_count;
<i> </i> $textarea_current_count_match = true;
<i> </i> $textarea_current_count = $textarea_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $textarea_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != true)
<i> </i> {
<i> </i> //Check if current Question's input type is a RadioButton or not.
<i> </i> //There are 3 RadioButton questions: $form_questions_radio_buttons_labels = array().
<i> </i> $radio_button_current_count = '0'; $radio_button_count_end = '2'; $radio_button_current_count_match = false;
<i> </i> while($value != $form_questions_radiobuttons_labels[$radio_button_current_count] || $radio_button_current_count != $radio_button_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_radio_buttons_labels[$radio_button_current_count]")
<i> </i> {
<i> </i> $current_radio_button_number = $radio_button_current_count;
<i> </i> $radio_button_current_count_match = true;
<i> </i> $radio_button_current_count = $radio_button_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $radio_button_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> if($current_value_matched != true)
<i> </i> {
<i> </i> //Check if current Question's input type is a DropDown or not.
<i> </i> //There are 3 DropDown questions: $form_questions_dropdowns_labels = array().
<i> </i> $dropdown_current_count = '0'; $dropdown_count_end = '2'; $dropdown_current_count_match = false;
<i> </i> while($value != $form_questions_dropdowns_labels[$dropdown_current_count] || $dropdown_current_count != $dropdown_count_end)
<i> </i> {
<i> </i> if($value == "$form_questions_dropdowns_labels[$dropdown_current_count]")
<i> </i> {
<i> </i> $current_drop_down_number = $dropdown_current_count;
<i> </i> $dropdown_current_count_match = true;
<i> </i> $dropdown_current_count = $dropdown_count_end;
<i> </i>
<i> </i> $current_value_matched = true;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> $dropdown_current_count++;
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i>
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a TextBox.
<i> </i> if($required_current_count_match == false && $textbox_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: </b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <input type="text" name="<?php echo $value_2;?>" value="<?php echo ${$value_2}; ?>"/>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a TextArea.
<i> </i> elseif($required_current_count_match == false && $textarea_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: </b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <textarea name="<?php echo $value_2;?>" rows="10" cols="30">
<i> </i> <?php
<i> </i> if ($id != '') //This $id is 'post id' & 'user id'.
<i> </i> {
<i> </i> echo ${$value_2};
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> echo "Write about yourself here.";
<i> </i> }
<i> </i> ?>
<i> </i> </textarea>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a RadioButton.
<i> </i> elseif($required_current_count_match == false && $radio_button_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: </b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <?php
<i> </i> foreach($form_radio_button_number_[$current_radio_button_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' && $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even <?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?>
<i> </i> <input type="radio" name="<?php echo $value_2;?>" value="<?php echo ${$value_2};?>" checked><?php echo ${$value_2};?>
<i> </i> <?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?>
<i> </i> <input type="radio" name="<?php echo $value_2;?>" value="<?php echo $value_3;?>"><?php echo $value_3;?>
<i> </i> <?php
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is NOT a REQUIRED one and is a DropDown.
<i> </i> elseif($required_current_count_match == false && $dropdown_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: </b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <select id="<?php echo $value_2;?>" name="<?php echo $value_2;?>">
<i> </i> <?php
<i> </i> foreach($form_dropdown_number_[$current_drop_down_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' && $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even <?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?>
<i> </i> <option value="<?php echo ${$value_2};?>" selected><?php echo ${$value_2};?></option>
<i> </i> <?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?>
<i> </i> <option value="<?php echo $value_3;?>"><?php echo $value_3;?></option>
<i> </i> <?php
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i> </select>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a TextBox.
<i> </i> if($required_current_count_match == true && $textbox_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: *</b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <input type="text" name="<?php echo $value_2;?>" value="<?php echo ${$value_2}; ?>"/>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a TextArea.
<i> </i> elseif($required_current_count_match == true && $textarea_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: *</b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <textarea name="<?php echo $value_2;?>" rows="10" cols="30">
<i> </i> <?php
<i> </i> if ($id != '') //This $id is 'post id' & 'user id'.
<i> </i> {
<i> </i> echo ${$value_2};
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> echo "Write about yourself here.";
<i> </i> }
<i> </i> ?>
<i> </i> </textarea>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a RadioButton.
<i> </i> elseif($required_current_count_match == true && $radio_button_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: *</b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <?php
<i> </i> foreach($form_radio_button_number_[$current_radio_button_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' && $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even <?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?>
<i> </i> <input type="radio" name="<?php echo $value_2;?>" value="<?php echo ${$value_2};?>" checked><?php echo ${$value_2};?>
<i> </i> <?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?>
<i> </i> <input type="radio" name="<?php echo $value_2;?>" value="<?php echo $value_3;?>"><?php echo $value_3;?>
<i> </i> <?php
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i> //If current Question's input type is a REQUIRED one and is a DropDown.
<i> </i> elseif($required_current_count_match == true && $dropdown_current_count_match == true)
<i> </i> {
<i> </i> //Need to replace 'Spaces' with '_'. And need to replace Upper Cases with Lower Cases as the 'name=" attributes are in lower cases with Under Scores instead of Spaces. Eg. Form Question Label 'Marital Status" is in form input field attribute "name='marital_status' or "id"='marital_status'".
<i> </i> $value_1 = str_replace(" ","_","$value"); //Replaced Spaces to Underscores.
<i> </i> $value_2 = strtolower($value_1); //Replaced Upper Cases to Lower Cases.
<i> </i> ?>
<i> </i> <div class="row">
<i> </i> <div class="col-25">
<i> </i> <label for="<?php echo $value_2;?>"><b><?php echo $value;?>: *</b></label>
<i> </i> </div>
<i> </i> <div class="col-75">
<i> </i> <select id="<?php echo $value_2;?>" name="<?php echo $value_2;?>">
<i> </i> <?php
<i> </i> foreach($form_dropdown_number_[$current_drop_down_number] as $value_3)
<i> </i> {
<i> </i> if($id != '' && $value_3 == ${$value_2})
<i> </i> {
<i> </i> //Even <?php echo "$value_3" is fine as both "$value_3" and "${$value_2}" hold same value. ${$value_2} is from database."
<i> </i> ?>
<i> </i> <option value="<?php echo ${$value_2};?>" selected><?php echo ${$value_2};?></option>
<i> </i> <?php
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> ?>
<i> </i> <option value="<?php echo $value_3;?>"><?php echo $value_3;?></option>
<i> </i> <?php
<i> </i> }
<i> </i> }
<i> </i> ?>
<i> </i> </select>
<i> </i> </div>
<i> </i> </div>
<i> </i> <?php
<i> </i> }
<i> </i>}
<i> </i>?>
<i> </i><input type="submit" name="submit" value="Submit" />
<i> </i></form>
<i> </i></div>
<i> </i></body>
<i> </i></html>
<?php
}
<i>
</i>foreach($form_questions_labels as $value) {
$required_current_count_match = false;
$textbox_current_count_match = false;
$textarea_current_count_match = false;
$radio_button_current_count_match = false;
$dropdown_current_count_match = false;
$current_value_matched = false;
// just use in_array() instead of a complicated while()?
if(in_array($value, $form_questions_required_labels)) {
$current_required_label_number = $required_current_count;
$required_current_count_match = true;
$required_current_count = $required_count_end; <br/>
$current_value_matched = true;
}
// whatever else happens after this...
}
foreach()
<i>
</i>$form_questions = array(
array(
'label' => 'First Name',
'required' => true,
'type' => 'text',
'name' => 'first_name'
),
array(
'label' => 'About Me',
'required' => false,
'type' => 'textarea',
'name' => 'about_me'
) // etc....
);
<i>
</i>$form_questions = array(array('label' => 'First Name','required' => true,'type' => 'text','name' => 'first_name'),array('label' => 'About Me','required' => false,'type' => 'textarea','name' => 'about_me') // etc....);
>@developer_web#1611824 Putting all your code in one line looks like this:
=>
->
$form_questions[0]['required']
<i>
</i>foreach($form_questions as $question) {
echo "<label for='{$question['name']}'>{$question['label']}";
if($question['required']) {
echo "*";
}
echo "</label>n";
// some if/else or switch/case statement here based on $question['type']
// to control what form element type gets output...
}
<i>
</i>// my previous example...
$form_questions = array(
array(
'label' => 'First Name',
'required' => true,
'type' => 'text',
'name' => 'first_name'
),
array(
'label' => 'About Me',
'required' => false,
'type' => 'textarea',
'name' => 'about_me'
)
);
// ...would become this ugly mess...
$form_questions = array();
$form_questions[0]['label'] = 'First Name';
$form_questions[0]['required'] = true;
$form_questions[0]['type'] = 'text';
$form_questions[0]['name'] = 'first_name';
$form_questions[1]['label'] = 'About Me';
$form_questions[1]['required'] = false;
$form_questions[1]['type'] = 'textarea';
$form_questions[1]['name'] = 'about_me';
0.1.9 — BETA 4.19