how to input and display multi lines in php/html form? - php

So i am new to using Linux VPS. I want to install softether on my VPS to protect myself when i play online multiplayer games. My VPS does not have much DDOS protection (because it is cheap)so i learned a technique called IP tables. There seems to be a lot of bad ip addresses in many databases that I found online. So i started to block IPs, but found that it takes a long time. I wanted to write an IP table generator to make my life easier. I wanted to use a subnet calculator on this form but i did not know how to code it, so i use a online site to get the subnet ip addresses of an ip i going to block.I thought it might be easier to just block all corporate and commercial asn ip addresses. but again i don't know where to start. That would be better for me to block ALL corporate/commercial IPs when i play my online games and i can just whitelist the IPs from my xbox live servers. please share your opinion(s). i want to have a safe time playing online without attackers flooding my internet.
i want to add multiple ip address inside my generator. but i cannot remember what shall I google to be able to learn how to do it. ALSO my php code is not working.
MY AIM to add multiple ip address and config them to rules, filters and chain rules. AND display them at the bottom clean (with line breaks) .
<html><head><style>.error {color: #FF0000;}</style></head><body>
<?php
$addressErr = $rulesErr = $filtersErr = $cRULEErr = "";
$address = $rules = $filters = $cRULE = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
(empty($_POST["address"])) {
$nameErr = "ip address is required";
} else {
$name = test_input($_POST["address"]);
if (!preg_match("/^[0-9 ]*$/",$address)) {
$addressErr = "Only numbers and white space allowed";
}
}
if (empty($_POST["rules"])) {
$rules = "Rules is required";
} else {
$rules = test_input($_POST["rules"]);
}
}
if (empty($_POST["filters"])) {
$filters = "Filters is required";
} else {
$filters = test_input($_POST["filters"]);
}
}
if(isset($_POST['generate'])){
if(!empty($_POST['cRULE'])){
foreach($_POST['cRULE'] as $selected){
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$data= $address + $rules + $filters + $cRULE + $selected."</br>";
echo $data "</br>"
?>
<p>
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>ip Table Generator v1</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="address">IP</label>
<div class="col-md-4">
<input id="address" name="address" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Multiple Radios (inline) -->
<div class="form-group">
<label class="col-md-4 control-label" for="rules">RULES</label>
<div class="col-md-4">
<label class="radio-inline" for="rules-0">
<input type="radio" name="rules" id="rules-0" value="ACCEPT" checked="checked">
accept
</label>
<label class="radio-inline" for="rules-1">
<input type="radio" name="rules" id="rules-1" value="DROP">
drop
</label>
<label class="radio-inline" for="rules-2">
<input type="radio" name="rules" id="rules-2" value="RETURN">
return
</label>
</div>
</div>
<!-- Multiple Radios (inline) -->
<div class="form-group">
<label class="col-md-4 control-label" for="filters">FILTERS</label>
<div class="col-md-4">
<label class="radio-inline" for="filters-0">
<input type="radio" name="filters" id="filters-0" value="INPUT" checked="checked">
input
</label>
<label class="radio-inline" for="filters-1">
<input type="radio" name="filters" id="filters-1" value="FORWARD">
forward
</label>
<label class="radio-inline" for="filters-2">
<input type="radio" name="filters" id="filters-2" value="OUTPUT">
output
</label>
</div>
</div>
<!-- Multiple Checkboxes (inline) -->
<div class="form-group">
<label class="col-md-4 control-label" for="cRULE">Chain Rules</label>
<div class="col-md-4">
<label class="checkbox-inline" for="cRULE-0">
<input type="checkbox" name="cRULE" id="cRULE-0" value="APPEND">
-A (Append)
</label>
<label class="checkbox-inline" for="cRULE-1">
<input type="checkbox" name="cRULE" id="cRULE-1" value="INTERFACE">
-i (interface)
</label>
<label class="checkbox-inline" for="cRULE-2">
<input type="checkbox" name="cRULE" id="cRULE-2" value="PROTOCOL">
-p (protocol)
</label>
<label class="checkbox-inline" for="cRULE-3">
<input type="checkbox" name="cRULE" id="cRULE-3" value="SOURCE">
-s (source)
</label>
<label class="checkbox-inline" for="cRULE-4">
<input type="checkbox" name="cRULE" id="cRULE-4" value="dPORT">
–dport
</label>
<label class="checkbox-inline" for="cRULE-5">
<input type="checkbox" name="cRULE" id="cRULE-5" value="TARGET">
-j (target)
</label>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="GEN"></label></br>
<div class="col-md-4">
<button id="GEN" name="GEN" class="btn btn-primary">GENERATE</button>
</div>
</div>
</fieldset>
</form>

Related

Empty / Null Return Value from Bootstrap Radio Button Group Selection

Would appreciate someone explaining to me why I only get an empty string back from PHP when trying to get radio-button group selection.
$currentlyemployed = null;
if (isset($currentlyemployedyes)) {
$currentlyemployed = "Yes";
}
else {
$currentlyemployed = "No";
}
NOTE: text inputs within the same form post and I can get their values.
Example snippets:
START FORM MARKUP
<div class="row">
<div class="col-sm-6 text-left">
<h5>Are you currently employed?</h5>
<div class="control-group">
<div class="controls">
<label>
<input type="radio" id="currentlyemployedyes" name="currentlyemployed" value="yes" />Yes</label>
<label>
<input type="radio" id="currentlyemployedno" name="currentlyemployed" value="no" />No</label>
<p class="help-block"></p>
</div>
</div>
</div>
</div>
END FORM MARKUP
START PHP CODE SNIPPET
$currentlyemployed = $_POST['currentlyemployed']; RETURNS empty string
/* FYI
$currentlyemployedyes = $_POST['currentlyemployedyes']; RETURNS "Yes"
$currentlyemployedno = $_POST['currentlyemployedno']; RETURNS "No"
*/
END PHP CODE SNIPPET
The code you have written works as expected. You can check out the snippet below.
Bootstrap or not it does not matter. The name="currentlyemployed" sent from the form to php server and then php binds it into $_POST associative global array.
<?php
echo "<pre>";
var_dump($_POST);
echo "</pre>";
echo "Currently Employed: ".$_POST['currentlyemployed'];
?>
<hr>
<div class="row">
<div class="col-sm-6 text-left">
<form method="POST">
<h5>Are you currently employed?</h5>
<div class="control-group">
<div class="controls">
<label>
<input type="radio" id="currentlyemployedyes" name="currentlyemployed" value="yes" />Yes</label>
<label>
<input type="radio" id="currentlyemployedno" name="currentlyemployed" value="no" />No</label>
<p class="help-block"></p>
</div>
</div>
<input type="submit">
</form>
</div>
</div>
I don't consider this a legitimate "answer", but, rather, a "work-around".
Would like to provide attribution, but forget where I found this, might have even been here on stack overflow.
<div class="row">
<div class="col-sm-6 text-left">
<h5>Are you currently employed?</h5>
<div class="control-group">
<div class="controls">
<label>
<input type="radio" id="currentlyemployedyes" name="currentlyemployed" value="yes" **onclick="$('#currentlyemployed').val('Yes');"** />
Yes</label>
<label>
<input type="radio" id="currentlyemployedno" name="currentlyemployed" value="no" **onclick="$('#currentlyemployed').val('No');"** />
No</label>
<p class="help-block"></p>
</div>
**<input name="currentlyemployed" id="currentlyemployed" type="hidden" value="" />**
</div>
</div>
</div>

how to take mutiple values from radio button in php

i have form with 4 radio buttons like
1) seth
2)roman
3)dean
4)others
if user clicks on others, a textbox will be open and user enters his own name
In php i want to take either form above 3 options whiich are selected by user or else from text box
if(isset($_POST['btnsave']))
{
$event = trim($_POST['event']);
$other_event = trim($_POST['other_event']);
$date = date("Y-m-d", strtotime($_POST['date']));
$info = trim($_POST['notes']);
$upd_date = date('Y-m-d H:i:s');//upl_date
$ucode = md5(uniqid(rand()));
if(empty($event) || ($other_event =='others' && empty($other_event)))
{
$errMSG = "Please enter camera name";
}
else
{
$event_name = ($event =='others') ? $other_event : $event;
echo $event_name;
}
}
?>
my form :
<div class="form-group">
<label class="control-label col-sm-3">Meal Preference</label>
<div class="col-sm-9">
<div class="checkbox">
<label>
<input type="radio" id="calorieCheckbox" name="event" value="VIRINCHI" style="margin-right: 8px;">seth
</label>
</div>
<div class="checkbox">
<label>
<input type="radio" id="saltCheckbox1" name="event" value="JOB_MELA " style="margin-right: 8px;">roman
</label>
</div>
<div class="checkbox">
<label>
<input type="radio" id="saltCheckbox2" name="event" value="MOCK_INTERVIEW" style="margin-right: 8px;"> dean
</label>
</div>
<div class="checkbox">
<label style="padding-bottom: 12px;">
<input type="radio" id="saltCheckbox3" onclick="ShowHideDiv()" value="others" style="margin-right: 8px;">others
</label>
</div>
<div class="col-sm-9" style="display: none;" id="others">
<input type="text" id="email" placeholder="Event type" name="other_event" class="form-control">
</div>
</div>
</div>
You are missing the name="event" attr from the value="others" radio.
And
if(empty($event) || ($other_event =='others' && empty($other_event)))
should be
if(empty($event) || ($event =='others' && empty($other_event)))

angularjs Post Object To PHP

how to create a variable of post json angularjs of code like the following:
<div class="form-group">
<label for="">Name</label>
<input type="text" name="name" required class="form-control" id="" ng-model="dataInsert.name" placeholder="">
<p ng-show="form.nama.$invalid && !form.nama.$pristine" class="help-block text-danger">Don't Empty.</p>
</div>
<div class="checkbox" ng-repeat="room in rooms">
<label>
<input type="checkbox" name="room" class="flat" ng-model="dataInsert.selectRoom[room.id]"> {{room.room}}
</label>
</div>
with php file like this
$data = json_decode(file_get_contents("php://input")); $name = $conn->real_escape_string($data->name); $room = $conn->real_escape_string($data->room???);
for the variable name works well, but I was confused to make variable from $ data-> room
Please help,

Divide form submissions evenly between two email addresses

I did search Stack Overflow to the best of my ability to make sure this has not been answered and I could not find anything.
I have a form on which you can select your nearest town, but in one specific town I have two branches.
Lets say... Cape Town has two branches across the street of each other...
(cpt1#mail.com and cpt2#anothermail.com)
What I want to achieve is that If 10 people select cape town the emails should be send as follows:
cpt1
cpt2
cpt1
cpt2
cpt1
cpt2
cpt1
cpt2
cpt1
cpt2
Does this make sense?
I basically want 1 locations mail to be split between two branches, 1 for you, 1 for you, etc etc.
I was thinking of putting them in an array and then use a random number between 1 and 2 to select the mail from the array, but I want to know what would be best here as I actually have no clue.
My current code is as follow:
HTML:
<fieldset>
<!-- Form Name -->
<legend>Contact Us</legend>
<!-- Name input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-4">
<input id="name" name="name" type="text" placeholder="Enter Name Here" class="form-control input-md">
</div>
</div>
<!-- E-mail input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">E-mail</label>
<div class="col-md-4">
<input id="email" name="email" type="text" placeholder="Enter E-mail Here" class="form-control input-md">
</div>
</div>
<!-- Select Town -->
<div class="form-group">
<label class="col-md-4 control-label" for="town">Town</label>
<div class="col-md-4">
<select id="town" name="town" class="form-control">
<option value="Cape Town">Cape Town</option>
<option value="Bellville">Bellville</option>
<option value="Pretoria">Pretoria</option>
<option value="Johannesburg">Johannesburg</option>
</select>
</div>
</div>
<!-- Message -->
<div class="form-group">
<label class="col-md-4 control-label" for="message">Message</label>
<div class="col-md-4">
<textarea class="form-control" id="message" name="message" placeholder="Enter Message Here"></textarea>
</div>
</div>
</fieldset>
PHP:
$town = $_POST['town'];
switch ($town) {
case 'capetown':
$email_address = 'capetown#me.com';
break;
case 'bellville':
$email_address = 'bellville#me.com';
break;
case 'pretoria':
$email_address = 'pretoria#me.com';
break;
default:
$email_address = 'headoffice#me.com';
}
mail($email_address, etc etc etc )
html edited to:
<html>
<body>
<form action="test.php" method="post">
<select id="town" name="town" class="form-control">
<option value="Cape Town">Cape Town</option>
<option value="Bellville">Bellville</option>
<option value="Pretoria">Pretoria</option>
<option value="Johannesburg">Johannesburg</option>
</select>
</form>
</body>
</html>
php edited to:
<?php
extract($_POST);
switch ($town) {
case '2':
$email_address = 'capetown#me.com';
echo($email_address);
break;
case '3':
$email_address = 'bellville#me.com';
echo($email_address);
break;
case '4':
$email_address = 'pretoria#me.com'; echo($email_address);
break;
default:
$email_address = 'headoffice#me.com'; echo($email_address);
}
?>
this code will prove u information which email select when u select perticular city!

While is $_FILE superglobal not being passed

So I am working on a file upload form that seems to lose the information in the file super global from one step to another. So what I do is I print out the file super global before I verify through captcha and then print it out once I validate through the captcha. For some way I lose the information after verifying the captcha. I have tried storing the information in a cookie and a session variable but with no luck. In terms of the cookie direction it saves the file super global information into the cookie only if I hit refresh before captcha validation. In terms of session storage it stores the information in the session variable before I verify the captch but then lose it after I verify the captach. Can you guys people help, and thanks in advance. My code is below:
$DIRECTORY_NAME = "/home/www/xxx/xxxPhotos/";
$FILES = array();
$SPEAKER_STATUS_DROPDOWN = '<option value="">...</option><option value="Suggested">Suggested</option><option value="Invited">Invited</option><option value="Confirmed">Confirmed</option>';
if (empty($_SESSION['captcha']) || strtolower(trim($_REQUEST['captcha'])) != $_SESSION['captcha']) {
$captcha = false;
} else {
$captcha = true;
}
if (!empty($_POST) && $captcha) {
$UNIQ_ID = $_POST['uniq_id'];
$FORM_ID = $_POST['form_id'];
//$uniqid = createuniqid();
// Upload file
if ($_FILES["file"]["name"] != "") {
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
die();
}
else
{
$allowedExtensions = array("jpg","gif","tiff","pdf");
if ($file["file"]['tmp_name'] != '') {
if (!in_array(end(explode(".",
strtolower($file["file"]['name']))),
$allowedExtensions)) {
die($file["file"]['name'].' is an invalid file type!<br/>'.
'<a href="javascript:history.go(-1);">'.
'<&lt Go Back</a>');
}
}
$filename = "AS_".$uniqid."". strrchr($_FILES["file"]["name"], '.');
move_uploaded_file($_FILES["file"]["tmp_name"],
$DIRECTORY_NAME . $filename);
$filenamequery = ", attachment='$filename' ";
$filenameemailbody = "<br>Attachment: http://www.verney.ca/viewabstract.php?filename=$filename";
}
die('reached here');
}
HTML Form
<form name="frmAbstract" id ="frmAbstract" method="post" action="storiesv.php" onSubmit="return validation();" enctype="multipart/form-data" style="margin-left:20px;">
<input type="hidden" name="uniq_id" value="">
<input type="hidden" name="form_id" value="6">
<div><label class="labelHeader"><strong><h1>Form</h1></strong></label><br/></div>
<div class="formrow">
<label for="question_390">First Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_390" name="question_390" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_391">Last Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_391" name="question_391" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_392">Title: </label>
<input type="text" id="question_392" name="question_392" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_393">Organization: </label>
<input type="text" id="question_393" name="question_393" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_394">Phone: </label>
<input type="text" id="question_394" name="question_394" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_395">Email: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_395" name="question_395" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_396">Involvement with the CBS: </label>
<input type="text" id="question_396" name="question_396" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_397">First became a CBS member in (yyyy): <span style="color:#FF0000">*</span></label>
<input type="text" id="question_397" name="question_397" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_398">Your story/experience/anecdote (limit of 250 words): </label>
<textarea name="question_398" name="question_398" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do you have a photo / graphic to upload (scans of print photos are acceptable)? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_0" name="question_399[]" value="Yes"><label for="question_399_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_1" name="question_399[]" value="No"><label for="question_399_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div>
<div>
<label for="question_400">Attachment: (Only jpg, gif, tiff, pdf, will be accepted) </label>
<input type="file" id="question_400" name="question_400" style="width:500px;">
</div>
<div class="formrow">
<label for="question_401">For photos submitted, please include names of people in the photo, location, and date. </label>
<textarea name="question_401" name="question_401" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do we have permission to publish this photo in a slide show to be featured at the 2014 CBS Conference and possibly in a printed collection of memoirs intended for past and present CBS members? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_0" name="question_402[]" value="Yes"><label for="question_402_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_1" name="question_402[]" value="No"><label for="question_402_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div><div><label class="labelHeader"><strong>Questions</strong></label><br/></div>
<div class="formrow">
<label for="question_404">Tell us about your experience(s) with the CBS. </label>
<input type="text" id="question_404" name="question_404" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_405">How did you become involved in the CBS? </label>
<input type="text" id="question_405" name="question_405" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_406">What is your best memory of the CBS? </label>
<input type="text" id="question_406" name="question_406" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_407">Who have been your role models in the field? </label>
<input type="text" id="question_407" name="question_407" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_408">What has been the most significant accomplishment of Canadian bioethics? </label>
<input type="text" id="question_408" name="question_408" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_409">What is our biggest challenge going forward? </label>
<input type="text" id="question_409" name="question_409" style="width:500px" maxlength="255" value="">
</div>
</fieldset>
<div style="clear:both;"><br><input type="submit" name="btnSave" id="btnSave" value="Next" class="submitbutton" "></div>
<p> </p>
</form>
So the code above is the original code I have been working with. It essentially does the file upload after the captcha is validated, and this is where I lose $_FILES super global
ANSWER: Thanks for all those who viewed my question. The issue was the captcha was in a form on it own page with a enctype set. Therefore the $_FILES super global was overwritten with that forms $_FILES, which of course is not set.
The name of your file input is question_400, so you would need $_FILES["question_400"]["name"], etc.

Categories