Form result not getting as expected

Issues related to forms.
Post Reply
User avatar
Biju
 
 
Posts: 197
Joined: Thu Mar 10, 2016 7:02 pm
Location: Kerala, INDIA.

Form result not getting as expected

Post by Biju » Mon Apr 29, 2019 8:40 am

I have a layout grid (form enabled) with two Edit boxes and two radio buttons.

Editbox1 for “name” (Direct entry by user)
Editbox2 for “status” (which is getting according to radio button selection - use condition)

My Radio button condition Settings:

Radiobutton1:
Condition: Selected
Action: Calculate
Target: Editbox2
Expression: “Yes”

Radiobutton2:
Condition: Selected
Action: Calculate
Target: Editbox2
Expression: “No”

Form is running with MySQL.

Everything works fine except “NAME” field of MySQL table shows Editbox1 value as “on” for all entries, even though I test with different names. This problem occurs only when selection done with radiobutton. If I manually input the Editbox2 value as "Yes" or "No" without using radiobuttons it works as expected.
~ Remain Curious
and Keep Learning ~

_________________
www.philip.epizy.com

User avatar
Pablo
 
Posts: 16730
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Form result not getting as expected

Post by Pablo » Mon Apr 29, 2019 8:55 am

What is the PHP code of the page?

User avatar
Biju
 
 
Posts: 197
Joined: Thu Mar 10, 2016 7:02 pm
Location: Kerala, INDIA.

Re: Form result not getting as expected

Post by Biju » Mon Apr 29, 2019 12:29 pm

<?php
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
function ReplaceVariables($code)
{
foreach ($_POST as $key => $value)
{
if (is_array($value))
{
$value = implode(",", $value);
}
$name = "$" . $key;
$code = str_replace($name, $value, $code);
}
$code = str_replace('$ipaddress', $_SERVER['REMOTE_ADDR'], $code);
return $code;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'layoutgrid2')
{
$mailto = 'yourname@yourdomain.com';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Website form';
$message = 'Values submitted from web site form:';
$success_url = './thanks.php';
$error_url = '';
$error = '';
$mysql_server = 'localhost';
$mysql_database = 'abraon';
$mysql_table = 'launch';
$mysql_username = 'root';
$mysql_password = 'pass';
$eol = "\n";
$boundary = md5(uniqid(time()));

$header = 'From: '.$mailfrom.$eol;
$header .= 'Reply-To: '.$mailfrom.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
if (!ValidateEmail($mailfrom))
{
$error .= "The specified email address is invalid!\n<br>";
}

if (!empty($error))
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $error, $errorcode);
echo $errorcode;
exit;
}

$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$message .= $eol;
$logdata = '';
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (!is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
}
}
}
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($message).$eol;
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0)
{
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
}
}
}
$body .= '--'.$boundary.'--'.$eol;
if ($mailto != '')
{
mail($mailto, $subject, $body, $header);
}
$search = array("ä", "Ä", "ö", "Ö", "ü", "Ü", "ß", "!", "§", "$", "%", "&", "/", "\x00", "^", "°", "\x1a", "-", "\"", " ", "\\", "\0", "\x0B", "\t", "\n", "\r", "(", ")", "=", "?", "`", "*", "'", ":", ";", ">", "<", "{", "}", "[", "]", "~", "²", "³", "~", "µ", "@", "|", "<", "+", "#", ".", "´", "+", ",");
$replace = array("ae", "Ae", "oe", "Oe", "ue", "Ue", "ss");
foreach($_POST as $name=>$value)
{
$name = str_replace($search, $replace, $name);
$name = strtoupper($name);
$form_data[$name] = $value;
}
$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password) or die('Failed to connect to database server!<br>'.mysqli_error($db));
mysqli_query($db, "CREATE DATABASE IF NOT EXISTS $mysql_database");
mysqli_select_db($db, $mysql_database) or die('Failed to select database<br>'.mysqli_error($db));
mysqli_query($db, "CREATE TABLE IF NOT EXISTS $mysql_table (ID int(9) NOT NULL auto_increment, `DATESTAMP` DATE, `TIME` VARCHAR(8), `IP` VARCHAR(15), `BROWSER` TINYTEXT, PRIMARY KEY (id))");
foreach($form_data as $name=>$value)
{
mysqli_query($db ,"ALTER TABLE $mysql_table ADD $name VARCHAR(255)");
}
mysqli_query($db, "INSERT INTO $mysql_table (`DATESTAMP`, `TIME`, `IP`, `BROWSER`)
VALUES ('".date("Y-m-d")."',
'".date("G:i:s")."',
'".$_SERVER['REMOTE_ADDR']."',
'".$_SERVER['HTTP_USER_AGENT']."')")or die('Failed to insert data into table!<br>'.mysqli_error($db));
$id = mysqli_insert_id($db);
foreach($form_data as $name=>$value)
{
mysqli_query($db, "UPDATE $mysql_table SET $name='".mysqli_real_escape_string($db, $value)."' WHERE ID=$id") or die('Failed to update table!<br>'.mysqli_error($db));
}
mysqli_close($db);
$successcode = file_get_contents($success_url);
$successcode = ReplaceVariables($successcode);
echo $successcode;
exit;
}
?>
~ Remain Curious
and Keep Learning ~

_________________
www.philip.epizy.com

User avatar
Pablo
 
Posts: 16730
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Form result not getting as expected

Post by Pablo » Mon Apr 29, 2019 1:09 pm

I'm sorry, but I need the complete code of the page, including the 'body'.

User avatar
Biju
 
 
Posts: 197
Joined: Thu Mar 10, 2016 7:02 pm
Location: Kerala, INDIA.

Re: Form result not getting as expected

Post by Biju » Mon Apr 29, 2019 2:03 pm

Hi Pablo,
I found the problem myself.

Both the Editbox1's "Name" and 'Radio Button's "Group name" was same. (i.e "name"). That is why the Radio button value "on" dispayed in that Name filed in MySQL.
Image
Image
WWB itself filled these fields. If it will be same there should be a warning from WWB.

Thanks..
~ Remain Curious
and Keep Learning ~

_________________
www.philip.epizy.com

Post Reply