Find an html element by id and replace its contents with php - php

I have an html with submit button.
Submit sends you to php.
php code has this:
header("location:./setupOk.html");
$html = file_get_html('setupOk.html');
$ret = $html->find('div[id=valueOk]');
echo $ret[0]->innertext = "foo";
and this is some of my html setupOk.html code:
<form action="http://54.186.92.18/Pixel-Matrix/keys.php" method="post">
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" />
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
</form>
After executing button on first html, it goes to php and reloads my html website with setupOk but no text is innered to anywhere. Any solution?
EDIT:
my goal is to have a general html (with label and images) then from php, put text to that html and automatically load this html on user's browser
EDIT2:
MY FIRST HTML ISN'T THE SAME THAN 2ND HTML. FIRST ONE SENDS POST PETITION TO PHP THEN DEPENDING ON THE INFO SENT TO PHP, PHP WILL FILL TEXT TO THE 2ND HTML AND LOAD THIS LAST HTML ON USER'S BROWSER

Avoiding DOMParser and loading/redirecting to HTML page -- you can do it more simple way like (it has to be a PHP file):
<?php
$innerText = "";
if (!empty($_POST['Key'])) {
$innerText = "foo";
}
?>
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" value="<?php echo $innerText;?>"/>
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
If you think this is not what you want - please elaborate your need a bit.
UPDATE
setupOk.php
<form action="http://54.186.92.18/Pixel-Matrix/keys.php" method="post">
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" />
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
</form>
keys.php [where you are submitting the form]
require_once('simple_html_dom.php');
$processedResult = "";
if (!empty($_POST['Key'])) {
$processedResult = "foo";
}
$html = file_get_html('setupOk.php');
$html->find('input[id=valOk]', 0)->value = $processedResult;
echo $html;
I have tested it and it's working.

Related

error while passing input value to the next page

below is the original code, and
<html>
<head>
<title>slider</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="slider-container">
<form action="asd.php" method="GET">
<input type="range" min="0" max="10" value="5" id="slider">
</form>
<div id="selector">
<div class="SelectBtn1"></div>
<div id="SelectValue"></div>
</div>
<div id="Progressbar"></div>
</div>
<div class="nextcontainer">
Result »
</div>
the asd.php
<body>
<div class="result-head">
<h1 class="main-title ng-binding">Your excrement..</h1>
</div>
<div class="result-container">
<h1 class="area">can support annually<?php echo $_REQUEST['slider'];?></h1>
</div>
</body>
I made html file and php file, and I tried to get response from the survey and try to show it in the next page(asd.php)
However, when I input and surf the next page, it shows pure code like the picture. What did I do wrong?
You have to use the attribute name instead of the attribute id because that is how it is passed on. For example you could do
<html>
<head>
<title>slider</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="slider-container">
<form action="asd.php" method="GET">
<input type="range" min="0" max="10" value="5" id="slider" name="slider">
</form>
<div id="selector">
<div class="SelectBtn1"></div>
<div id="SelectValue"></div>
</div>
<div id="Progressbar"></div>
</div>
<div class="nextcontainer">
Result »
</div>

cant duplicate a value from database on php

i am making a dynamic form right now, duplicating the form is easy, but there is one textfield where the value is from the database, the problem is, the value from the database cant be duplicated. the point is im trying to duplicate a value in php, here is the problem, and is there anyway to insert a data into database using <label> ? because duplicating the value using <label> is a succsed
here is my code.
<?php
include 'config/db_connect.php';
if(isset($_POST['submit'])){
for($i = 0; $i <= count($_POST['kode'])-1;$i++){
$selectidmax =mysqli_query($con, "SELECT max(jenis) as maxjenis FROM t_produk WHERE jenis LIKE 'SS%'");
$hslidmax=mysqli_fetch_array($selectidmax);
$idmax=$hslidmax['maxjenis'];
$nourut = (int) substr($idmax, 2,3);
$nourut++;
$IDbaru = "SS" . sprintf("%03s", $nourut);
$kodep = $_POST['kode'][$i];
$kodeproduk = $_POST['kp'][$i];
$produk = $_POST['produk'][$i];
$bunga = $_POST['bunga'][$i];
$ket = $_POST['ket'][$i];
$query = mysqli_query($con, "INSERT INTO t_produk(kode_cu,jenis,kode_produk,produk,bunga,keterangan)
VALUES (
'$kodep',
'$IDbaru',
'$kodeproduk',
'$produk',
'$bunga',
'$ket')
");
}
if($query){
header("location:home_cu.php");
}else{
echo "gagal" . mysqli_error($con);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Form Simpanan Saham</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style1.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="w3-bar w3-black">
Home
Menu Data Cu
Menu Data Kebijakan
Menu Data Modifikasi
</div>
<br>
<div class="container">
<form action="form_saham.php" method="post">
<h1 class="text-center">Produk Pinjaman</h1>
<div class="form-content">
<div class="row">
<div class="col-md-12">
<p><button type="button" id="btnAdd" class="btn btn-primary">Add More</button></p>
<br/>
</div>
</div>
<div class="row group">
<div class="col-md-3">
<div class="form-group">
<?php
include 'config/db_connect.php';
$kode = $_GET['kode_cu'];
$query = mysqli_query($con,"SELECT * FROM t_cu WHERE kode_cu = '$kode'");
while ($hasil = mysqli_fetch_array($query) ) {
?>
<label>Kode Produk :</label>
<input type="text" value="<?php echo $hasil['kode_cu']?>" name="kode[]" class="form-control">
<input type="text" name="kp[]" class="form-control"/>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Produk</label>
<input type="text" name="produk[]" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Bunga</label>
<input type="text" name="bunga[]" class="form-control">
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label>Keterangan</label>
<textarea name="ket[]" class="form-control" rows="3"></textarea>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button type="button" class="btn btn-danger btnRemove">Remove</button>
</div>
</div>
</div>
</div>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<?php } ?>
<script src="assets/js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="assets/js/bootstrap.min.js"></script>
<script src="jquery.multifield.min.js"></script>
<script>
$('.form-content').multifield({
section: '.group',
btnAdd:'#btnAdd',
btnRemove:'.btnRemove',
});
</script>
</body>
</html>
Ok, i found the question by myself, i just move the <input type="text" value="<?php echo $hasil['kode_cu']?>" name="kode[]" class="form-control"> to the top, so this textfield won't get duplicated, and then in the database value i changed the '$kodep', into (SELECT kode_cu FROM t_cu WHERE kode_cu = '$kodep'), Thank you for everyone who tries to help

HTML Form Sent to Email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I'm having an issue with my html form sending to my email.
I have it set up so that it goes to a php file and it works fine, but when I change the filename from index.php to contact.php it doesn't send anymore.
contact.php:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style/stylesheet.css">
<script src="script/scripts.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>
<div class="banner">
<img src="images/banner.jpg">
</div>
<div class="navigation">
<div class="navbar">
Home
News
<div class="dropdown">
<button class="dropbtn">Parts
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Cases
Motherboards
Processors
Graphics Cards
Storage
Power Supplies
RAM
Other
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Builds
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
Placeholder
</div>
</div>
<div class="contact" id="navright">
Contact
</div>
</div>
</div>
<div class="contact_page">
<form class="contact_form" action="contactform.php" method="post">
<label>Full Name:</label><br/>
<input type="text" name="name" placeholder="Full Name"><br/>
<label>Your Email:</label><br/>
<input type="text" name="mail" placeholder="Email"><br/>
<label>Subject:</label><br/>
<input type="text" name="subject" placeholder="Subject"><br/>
<label>Message:</label><br/>
<textarea name="message" class="contacttext" placeholder="Message..."></textarea><br/>
<button class="submit" type="submit">Submit</button>
</form>
</div>
<div class="footer">
<div class="footertext">
<p>Here at Terry's Computers we do not claim to own any of
the products showed on this website.</p>
<p>Contact Us</p>
</div>
</div>
</body>
</html>
contactform.php:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "terryjtowell#terrytowell.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an Email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contact.php?mailsend");
}
?>
It's not my web hoster because it worked with this file.
index.php:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta charset="UTF-8">
<title>Email Form</title>
</head>
<body>
<main>
<p class="header">E-MAIL FORM</p>
<form class="contact-form" action="contactform.php" method="post">
<p class="title">Your Name</p>
<input type="text" name="name" placeholer="Full Name"><br/>
<p class="title">Your E-Mail</p>
<input type="text" name="mail" placeholer="Your E-mail"><br/>
<p class="title">Subject</p>
<input type="text" name="subject" placeholer="Subject"><br/>
<p class="title">Message</p>
<textarea name="message" maxrows="10" placeholder="Message"></textarea><br/>
<button type="submit" name="submit"><h2>SUBMIT</h2></button><br/>
</form>
</main>
</body>
</html>
Your PHP line:
if (isset($_POST['submit'])) {
Will never execute because you need an element with the name of submit, but you have:
<button class="submit" type="submit">Submit</button>
Which you have in the example you say works. The solution should be as simple as adding a name attribute like this:
<button class="submit" name="submit" type="submit">Submit</button>

How would this be better written For adding php external data to a jquery select

I want to submit an app using phonegap, My app uses a lot of php which i know apple do not like so much and just decline the app and say its best to have a web app. I have an example index.html here
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>
</title>
<link rel="stylesheet" href="css/logout-button.min.css" />
<link rel="stylesheet" href="css/jquery.mobile-1.3.0.min.css" />
<link rel="stylesheet" href="css/my.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</script>
<script src="js/jquery.mobile-1.3.0.min.js"></script>
<script src="js/jquery.cookies.2.2.0.min.js"></script>
<script type="text/javascript">
var uid = $.cookies.get( 'uid' );
if(uid == null)
{
window.location ='account-login.html'; }
else
{ }
</script>
</head>
<body>
<div data-role="page" id="index4">
<div data-theme="a" data-role="header">
<a data-role="button" data-direction="reverse" data-rel="back" data-transition="slide"
data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
Back
</a>
<h3>
Event Details
</h3>
</div>
<div data-role="content">
<form id="eventForm" name="eventForm">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="event">
Event
</label>
<input name="eventname" id="eventname" placeholder="eventname" value="" type="text" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="about">
About
</label>
<textarea name="about" id="about" placeholder="about" value=""></textarea>
</fieldset>
</div>
<div data-role="fieldcontain">
<label for="dates">
Choose Dates
</label>
<div id="with-altField"></div>
<input type="hidden" id="altField" name="dates">
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="enddate">
End Date
</label>
<div id="with-altfield1"></div>
<input type="hidden" id="altField1" name="enddate">
</fieldset>
</div>
<div data-role="fieldcontain">
<script>
$.get('event-details.php', function(data){
$('#yourdiv').html(data);
});
</script>
<div id="yourdiv"></div>
</div>
<div data-role="fieldcontain">
<label for="manual">Add Emails</label>
<textarea cols="40" rows="8" name="emails" id="emails"></textarea>
</div>
<input type="submit" value="Submit" id="submitEventButton">
</form>
</div>
</div>
</body>
</html>
I call event-details.php here
<?
require_once("../backend/functions.php");
dbconn();
$id = $CURUSER["id"];
$res = "SELECT username,email,status FROM users left join cal_contacts on cal_contacts.contactid = users.id WHERE cal_contacts.userid = $id";
$res1 = mysql_query($res);
?>
<label for="select-choice-1" class="select">
Choose Contacts:
</label>
<select name="contacts[]" id="contacts" multiple="multiple" data-native-menu="false">
<?
while($row = mysql_fetch_array($res1))
{
print "<option value=$row[email]>$row[email] ($row[status])</option>";
}
?>
</select>
<?
I have the select-menu created through php. I was wondering if there was another way to do this so the complete select html doesn't have to be on the php script. This would mean that it would be harder for me to change my app once submitted and i'm sure apple would accept it alot easier.
If your problem is just to remove the PHP processing on that HTML, you could just move it somewhere else as a web service then get it via ajax request. Then you can just use json, etc. to fetch the data and populate your select menu.
here is a doc on jquery! regarding how to make ajax requests.
i found a tutorial here which seem similar on what you want to achieve.
How To Write A Simple PHP/MySQL Web Service for an iOS App!

appending php into a div and maintaining the current css

Okay.. this is the file lo_add.php:
<div class="rowElem">
<label>Item <? echo $i ?>:</label>
<div class="formRight searchDrop">
<select name="lo_item[]" class="chzn-select" data-placeholder="Choose an Item">
<option value=""></option>
<? $item_query = mysql_query("select id,code,title,price from items where domain_id='$domain_id' order by code");
while ($items = mysql_fetch_array($item_query)) { ?>
<option value="<? echo $items["id"] ?>"><? echo $items["code"]." - ".$items["title"]." - RM".$items["price"] ?></option>
<? } ?>
</select>
</div>
<label>Delivery Address :</label>
<div class="formRight searchDrop">
<select name="lo_site[]" class="chzn-select" data-placeholder="Choose a Delivery Address">
<option value=""></option>
<? $site_query = mysql_query("select id,name from sites where domain_id='$domain_id' order by name");
while ($sites = mysql_fetch_array($site_query)) { ?>
<option value="<? echo $sites["id"] ?>"><? echo $sites["name"] ?></option>
<? } ?>
</select>
</div>
<div class="fix"></div>
<label>Quantity:<span class="req">*</span></label>
<div class="formRight onlyNums">
<input type="text" name="lo_quantity[]" id="lo_quantity[]"/>
</div>
<div class="fix"></div>
</div>
And this is the html file that calls the css and what have you in the beginning:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title>Mecacom Technologies® Maintenance System © 2012</title>
<link href="/css/main.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Cuprum' rel='stylesheet' type='text/css' />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#addElement').click(function() {
var data = '';
$.get('/ajax/lo_add.php', data, function(response){
$('#hello').append(response);
});
});
});
</script>
</head>
<body>
<div class="content" id="container">
<div class="title"><h5>Record New Local Order</h5></div>
<form action="<? echo $PHP_SELF ?>?add=1" id="valid" class="mainForm" method="post" enctype="multipart/form-data">
<fieldset>
<div class="widget">
<div class="head"><h5 class="iLocked2">New Local Order Credentials</h5></div>
<div class="rowElem noborder">
<label>Order ID:<span class="req">*</span></label>
<div class="formRight">
<input type="text" class="validate[required]" name="order_id" id="order_id"/>
</div>
<div class="fix"></div>
</div>
<div class="rowElem noborder">
<label>Order Date:<span class="req">*</span></label>
<div class="formRight">
<input type="text" name="order_date" class="datepicker validate[required]" />
</div>
<div class="fix"></div>
</div>
<div id="hello"></div>
<div class="fix"></div>
Click To Append More Item
<input type="submit" value="Next" class="greyishBtn submitForm" />
<div class="fix"><input type="hidden" name="addnow" value="1" /></div>
</div>
</fieldset>
</form>
</div>
</body>
</html>
sigh .. quite a handful ... How do you think that the css aren't being rendered correctly after the jquery append?
I can see from your live test page that you are using Chosen to process the dropdowns and jQuery validation plugin to validate the quantity field.
The first thing is to make sure you call chosen() on the newly created dropdowns. This has to be called for new elements, because Chosen doesn't only rely on CSS, but changes the entire HTML structure of the dropdowns. So add this line, following your append,
$(".chzn-select").chosen()
Second is to make sure you validate the newly created quantity textfields by calling validate() on them, or re-calling whatever javascript you called to initialize the validate plugin.

Categories