Skip div within div simple html dom - dom

A page that I want to scrape data from has the following elements
<div class="content">
<p>I want this</p>
<p>I want this</p>
<div class="row">
<p>I do not want this</p>
<p>I do not want this</p>
</div>
</div>
I do not want paragraphs in the <div class="row">
This is what I have tried so far. Doesnt seem to work
foreach ($sample_html->find('div[class=entry-content]') as $content) {
foreach($content->find('div[class=row]') as $row){
foreach ($row->find('p') as $skip) {
$skip->outertext = '';
}
}
foreach($content->find('p') as $paragraph){
//echo $paragraph;
$paragraphs .= '<p>'.$paragraph->innertext.'</p>';
echo $paragraphs;
}
}

Change
$skip->outertext = '';
to
$skip->innertext= '';

Related

storing form and rout

I have problem on storing form . All my efforts will be damaged if I could not solve it.
The GET method is not supported for this route. Supported methods: POST.
what happen now :
1.When I press on register which is linked to this rout :
Route::POST('/jobs/apply/{id}/', [JobseekerController::class,'applyforjob'])->name('aplpy1');
there will be two scenarios:
if the user has cv it will register the user directly.(works)
if the user has not cv it will direct the user to create cv view .(works)
This is a part of create cv view :
<form method="POST" action="{{route('storing')}}" enctype=multipart/form-data>
#csrf
<input type="hidden" name=job_id value= {{$s}}>
#if (count($errors) > 0)
<div class="alert alert-danger alert-dismissible fade show">
<strong>Opps!</strong> Something went wrong, please check below errors.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#endif
<div class="card-body">
<div class="container">
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="accordion" class="checkout">
<div class="panel checkout-step">
<div> <span class="checkout-step-number">1</span>
<h4 class="checkout-step-title"> <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" > Personal Information</a></h4>
</div>
<div id="collapseOne" class="collapse in">
<div class="checkout-step-body">
<div class="row mt-3 pr-3">
<div class="col-6 ">
<strong>Full Name:</strong>
{!! Form::text('FName', null, array('placeholder' => 'Full Name','class' =>
'form-control pb-4')) !!}
</div>
<div class="col-6">
<div class="row mt-3 mr-2">
<strong>Nationality:</strong>
<select name="Nationality" class="custom-select">
#foreach(\App\Models\Nationality::all() as $nation)
<option value="{{$nation->name}}">{{$nation->name}}</option>
#endforeach
</select>
</div>
<div class="form-group ">
<button type="submit" name="submit" class="btn btn-primary ">{{ __('APPLAY') }}</button
</div>
<input type="hidden" name=job_id value= {{$s}}>
</form>
2.Now Here is the problem:
If I fill all the fields on the form correctly and click apply it works , but if there is missing field or anything not filled as it should be and then click apply , although there is validation on controller it does not work it gives this error:
The GET method is not supported for this route. Supported methods: POST.
Although I am using Post this my rout that I use to store the form
Route::POST('/jobsapply', [JobseekerController::class,'store'])->name('storing');
This my controller for storing:
public function store(Request $request )
{
$this->validate($request, [
'FName' => 'required|alpha|regex:/^([^"!\*\\]*)$/',
'Nationality' => 'required',
]);
$input = $request->all();
$input = $request->except(['_token']);
$cv = new cv();
if ($this->cvsave($cv, $request )) {
$data = Job::all();
$cv = auth()->user()->cv;
return view ('show',compact('cv' ,'data'))->with('success', 'CV created successfully.');
}
$data = Job::all();
return view('show')->with('Failed!', 'error');
}
public function cvsave(cv $cv, Request $request)
{
$cv->FName = $request->FName;
$cv->Nationality = $request->Nationality;
if ($cv->save()) {
$application = new JobApplication;
$id=$request->job_id;
$jobs = Job::find($id)->get();
$application->job_id =$request->job_id;
$user = User::find(auth()->user()->id);
$application->user_id = auth()->user()->id;
$cv = auth()->user()->cv;
$i= $cv->id;
$application->cv_id = $i;
$application->save();
\Session::flash('success', 'Thank you for applying! Wait for the company to respond.!');
return true;
}
return false;
}
I could not know the reason, I have read lots of stuff but still the same error

wrap content elements in specific pages differently

All of my content elements are wrapped using stdWrap.wrap.
I am looking for a solution to wrap content elements in the page which i have my ke_search added differently .
Why do you need another HTML-markup?
Normaly you have another <div> around your search results which should enable you to add another styling by CSS.
your page may look like:
<body>
<div class="header">
:
</div>
<div class="content">
<div id="C123">
<h3>my very special CE</h3>
<p class="bodytext">with some text to demonstrate.</p>
</div>
<div id="345">
<h3>your search results:</h3>
<div class="search-results">
<a href="index.php?id=67&s=special">
<div id="C123">
<h3>my very special CE</h3>
<p class="bodytext">with some text to demonstrate.</p>
</div>
</a>
<a href="index.php?id=83&s=special">
<div id="C52">
<h2>just a demo</h3>
<p class="bodytext">this text is nothing special.</p>
</div>
</a>
</div>
</div>
</div>
</body>
with appropiate CSS the first CE looks completely different to the same CE in the search results.
h3 { color:black; font-size:16px; }
p.bodytext { color:#444; font-size:12px; }
.search-results h3 { color:blue; font-size:10px; font-weight:bold; }
.search-results p.bodytext { color:#44b; font-size:10px; font-style:italics; }
I answer my own question:
You can conditionally wrap specific content elements using the following typoscript snippet.
tt_content {
stdWrap {
if.value = tx_kesearch_pi2
{
wrap = |
innerWrap >
}
wrap = <div class="someotherclass">|</div>
}
}

codeigniter upload form not working

I've never used code igniter and I'm trying to make a quick admin form that includes an image upload input. My admin form is up and has a route/url that I can reach, but the save function is not working correctly. I'm getting a 404 error when I click my submit button.
I believe the issue is with the line form_open_multipart('dashboard_save/do_upload') in views/admin/Dashboard.php. I don't think the do_upload function is being reached. Any ideas where I'm going wrong?
*new detail: I am able to reach my controller with form_open_multipart('dashboard_save') using an index function... but I'm not able to reach any other function such as form_open_multipart('dashboard_save/upload') using an upload function in controller dashboard_save.
CONTROLLERS
controllers/admin/Dashboard_save.php
<?php
class Dashboard_save extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index()
{
// die('got here 2');
$this->load->view('admin/dashboard_view', array('error' => ' ' ));
}
public function do_upload()
{
// die('got here!!');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('dashboard_view', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('dashboard_save', $data);
}
}
}
?>
VIEWS
views/admin/Dashboard.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');?>
<!DOCTYPE html>
<body>
<div id="main-wrapper">
<div id="main-container">
<div id="main-body">
<div id='main-form-body'>
<p>Configure front end here.</p>
<div id='admin-form-container'>
<?php echo form_open_multipart('dashboard_save/do_upload');?>
<form id="admin-form" method="" action="">
<div class='form-field'>
<div class='label-wrapper'><label for='main_img'>Main Image</label></div>
<input type = "file" name = "userfile" size = "20" />
</div>
<div class='form-field'>
<button id="submit-search" type="submit" class="button" title="Submit" value = "upload">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
views/admin/Dashboard_save.php
<html>
<head><title>Dashboard Save</title></head>
<body>
<h3>testing dashbord submit</h3>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</body>
</html>
Hi first to check your do_upload function has been called or not . if yes then to please check you have loaded in upload library or not . if not so please upload library and than to use below code
<?php defined('BASEPATH') OR exit('No direct script access allowed');?>
<!DOCTYPE html>
<body>
<div id="main-wrapper">
<div id="main-container">
<div id="main-body">
<div id='main-form-body'>
<p>Configure front end here.</p>
<div id='admin-form-container'>
<form id="admin-form" method="post" action="<?php echo base_url()?>/dashboard_save/do_upload" enctype="multipart/form-data">
<div class='form-field'>
<div class='label-wrapper'><label for='main_img'>Main Image</label></div>
<input type = "file" name = "userfile" size = "20" />
</div>
<div class='form-field'>
<button id="submit-search" type="submit" class="button" title="Submit" value = "upload">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
You have used two times the form tag. This is why its taking last one and showing error. Remove one FORM tag. Here is your view file code revised
<?php defined('BASEPATH') OR exit('No direct script access allowed');?>
<!DOCTYPE html>
<body>
<div id="main-wrapper">
<div id="main-container">
<div id="main-body">
<div id='main-form-body'>
<p>Configure front end here.</p>
<div id='admin-form-container'>
<?php $attributes = array('id' => 'admin-form'); echo form_open_multipart('dashboard_save/do_upload', $attributes);?>
<div class='form-field'>
<div class='label-wrapper'><label for='main_img'>Main Image</label></div>
<input type = "file" name = "userfile" size = "20" />
</div>
<div class='form-field'>
<button id="submit-search" type="submit" class="button" title="Submit" value = "upload">Submit</button>
</div>
<?php echo form_close();?>
</div>
</div>
</div>
</div>
</body>
</html>
No test it. I have removed form open & close tag which you wrote manually, at same time use only form_open_multipart() & form_close() for accomplish same task

PHP form submits regardless of required/error handling attempts

newbie here
I am currently attempting to build a simple contact form to learn how best to build one. I've tried to make several fields required (name, email, do you like spam radio button). The required html5 element isn't working for me or I am not implementing it correctly based on what i've read here, on google and other places. Likewise the error/require messages don't display if someone attempts to submit a message. Instead the form goes through on submit even if NO content anywhere has been entered. I built this yesterday and have been working on the errors for about 24 hours now and am hoping to find some help here.
I currently am returning no errors, the form sends all information entered as hoped, but it also sends if NO information is entered and that doesn't seem like the best possible form to me. I've tried to build a function to help the required, but that doesn't seem to be working either.
Again, i'm new so if my mistakes are obvious and silly, please help em to understand them, that would be greatly appreciated.
current example can be found here
My code:
<!-- For PoohPot -->
<style TYPE="text/css">
input[type="text"]#website { display: none; }
input#website { display: none; }
.vSmall {font-size: 50%; text-align: center;}
</style>
<script>
$('form').submit(function(){
if ($('input#website').val().length != 0) {
return false;
}
});
</script>
<?php
//template.php
include '_inc/config.php';//holds arrays, et al.
include '_inc/functions.php';//holds functions that call arrays, etc
include '_inc/head.php';//Begin Document
//include '_inc/header.php';//Begin Content
?>
<article class="container box style3">
<header>
<img src="_img/icons/icon_lg-max-o-matic2.png" alt="php icon">
<h2><?=NAME_SITE?></h2>
<p>Spam Survey</p>
</header>
<?php
$to = "chezshire#gmail.com";
$subject="Spam Survey";
//----- end conf ----- //
// define variables and set to empty values
$nameErr = $emailErr = $spamErr = "";
$userName = $userEmail = $userMessage = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["userName"]))
{$nameErr = "* Name is required";}
else
{$name = testInput($_POST["userName"]);}
if (empty($_POST["userEmail"]))
{$emailErr = "* Email is required";}
else
{$email = testInput($_POST["userEmail"]);}
if (empty($_POST["spamErr"]))
{$emailErr = "* You must select an option";}
else
{$email = testInput($_POST["userEmail"]);}
if (empty($_POST["userMessage"]))
{$comment = "";}
else
{$comment = testInput($_POST["userMessage"]);}
}
if(isset($_POST['userName']))
{//data is submitted, show it
//echo $_POST['userName'];
$text = 'From: ' . $_POST['userName'] . PHP_EOL;
//$text .= $_POST['Comments']; //add on to text
$text .= process_post(); // uses proces_post to handle comments and stuff
$from = $_POST['userEmail'];
/*
echo '<pre>';
var_dump($_POST);
echo '</pre>';
*/
//domain spoofing controls
$headers = 'From: noreply#max-o-matic.com' . PHP_EOL . //from where formhandler sits
'Reply-To: ' . $from . PHP_EOL . //where replies are to go to
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $text, $headers); //from becomes headers
echo '<div class="row">
<div class="12u">
<p>Thanxs!</p>
<p>
<br />RESET
</p>
</div>
</div>
</article>
';
/*
echo '<pre>';
var_dump($_POST);
echo '</pre>';
*/
}else{//no data, show form
echo '
<form action="' . THIS_PAGE . '" method="post">
<div class="row half">
<div class="6u">
<input type="text" class="text" name="userName" placeholder="Name?" required autofocus />
<span class="error"><?php echo $nameErr;?></span>
</div>
<div class="6u">
<input type="text" class="text" name="userEmail" placeholder="Email" required />
<span class="error"><?php echo $emailErr;?></span>
</div>
</div>
<div class="row half">
<div class="6u">
Do you like spam?<br />
<input type="radio" name="Please_Spam_Me" value="YES!" required value="1" />Yes<br />
<input type="radio" name="Please_Spam_Me" value="NO!" />No<br />
<span class="error"><?php echo $spamErr;?>
</div>
<div class="6u">
How much Spam is too much?<br />
<input type="checkbox" name="checkbox-group" class="group-required" id="checkbox-group-id" value="6+" >6 or more<br />
<input type="checkbox" name="checkbox-group" value="2+">2 to 5<br />
<input type="checkbox" name="checkbox-group" value="Any">ANY<br /><br />
</div>
</div>
<!--For Winnie the Pooh -->
<input id="website" name="website" type="text" value"Website" />
<div class="row half">
<div class="12u">
<textarea name="userMessage" placeholder="What is your opinion on Spam?"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li>SEND!</li>
<input type="submit" />
</ul>
<p class="vSmall">
* Please note, instead of a reCaptcha I build my own \'honeypot\' from scratch.
</p>
</div>
</div>
</form>
</article>
';
}
function testInput($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
// this is a function
function process_post()
{//loop through POST vars and return a single string
$myReturn = ''; //set to initial empty value
foreach($_POST as $varName=> $value)//$_POST is an array
{#loop POST vars to create JS array on the current page - include email
$strippedVarName = str_replace("_"," ",$varName);#remove underscores
if(is_array($_POST[$varName]))
{#checkboxes are arrays, and we need to collapse the array to comma separated string!
$myReturn .= $strippedVarName . ": " . implode(",",$_POST[$varName]) . PHP_EOL;
}else{//not an array, create line
$myReturn .= $strippedVarName . ": " . $value . PHP_EOL;
}
}
return $myReturn;
}
include "_inc/footer.php";//End Content/Document
?>
If you're trying to use HTML5 stuffs then you need the HTML5 doctype. Place this at the start of your output and see what happens:
<!DOCTYPE html>
Also, typo value"Website" should be value="Website"

How to parse many div's using Simple HTML DOM?

I have this HTML code
<div id="first" class="first">
One
<div id="second" class="second">
Second
<div id="third" class="third">
Third
<div id="fourth" class="fourth">
Fourth
<div id="fifth" clas="fifth">
Fifht
<div id="sixth" class="sixth">
Sixth
</div>
</div>
</div>
</div>
</div>
</div>
This code is from an external website.
I want to display 'Hi' using Simple HTML DOM from a URL.
Do you want to see something like this?
$el = $html->find("#first", 0);
while ($child = $el->children(1)) {
$el = $child;
}
echo $el->innertext;