Please help me, I wanted to do a post method using an anchor tag.
Here is the sample code:
<form action="essay2.php" id="quiz" name="quiz" method="post">
<ul>
<li>
2
</li>
</ul>
<input type="text" name="test1">
</form>
And the PHP code:
<?php
session_start();
if (isset($_POST['submit-test'])) {
$_SESSION['test1'] = $_POST['test1'];
header("Location: essay2.php"]);
}
?>
To elaborate on my comment above...
You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link
consider this approach
button[name="submit-test"] {
background: transparent;
border: 0 none;
color: blue;
text-decoration: underline;
font: inherit;
cursor: pointer;
}
<form action="essay2.php" id="quiz" name="quiz" method="post">
<ul>
<li>
<button name="submit-test" type="submit">2</button>
</li>
</ul>
<input type="text" name="test1">
</form>
Results in the following sent when you click the "2"
You can use javascript with the onclick method on your link.
click to send
You also need to put a id to your form tag (id="myform" in this case).
This is how I would do:
<form action="essay2.php" id="quiz" name="quiz" method="post">
<ul>
<li>
2
</li>
</ul>
<input type="text" name="test1">
<input type="hidden" name="submit-test">
</form>
Use the tag inside the like this :
<button type="submit" name="submit-test"><a href="essay2.php"> 2 </button>
Related
I want to add margin to this <div>:
$notification_list .= "
<div class='FriendRdiv'>
<a href='main.php?u=".$initiator."'>
<img src='../img/".$pr."' id='FriendRPP'>
</a>
<a id='FriendRfrom'>".$initiator." sent you a friend request</a>
</div>
<form class='FriendRForm Rejecat' onsubmit='return false'>
<input type='submit' value='Reject' id='Reject'>
</form>
<form class='FriendRForm' onsubmit='return false'>
<input type='submit' value='Accept' id='Accept'>
</form>";
I don't know how many notifications I will get, so I want each <div> to have a bigger margin than one before it.
you can use style attribute
<div class='FriendRdiv' style="margin: 10px;">
or you can use css for that in css file
.FriendRdiv{
margin: 10px;
}
I have been trying to mimick the nested comment system that reddit use. Now i have a app that does in a way look like what it was intended to look. But, if you have a look at the reddit style:
I haven't been able to reproduce the lines that attach the previous answer.
My thought is that is nested divs somehow.
currenlty I'm outputting the db data lik this:
<?php if(!empty(getMessage())): ?>
<div class="container">
<h1>The nested comment exampel!</h1>
<?php foreach (getMessage() as $value){ ?>
<div class="level_<?= $value->level; ?> comment" id="<?= $value->id; ?>">
<?php if($value->visible == 0) : ?>
<?= $value->date ?><br>
Deleted
<?php elseif($value->visible == 1): ?>
<?= $value->date ?> X <?= 'id: '. $value->id . ', sort order: ' .$value->sort_order . ', level: '.$value->level ;?><br>
<?= $value->comment_text ?>
<form action="index.php" method="post">
<input type="hidden" name="id" value="<?= $value->id ?>" />
<input type="hidden" name="parent" value="<?= $value->reply_to ?>" />
Add comment: <input type="text" name="svar">
<input type="submit">
</form>
<?php endif; ?>
</div>
<?php } endif; ?>
</div>
And i have solved the left margin with a simpel (not so clean) solution with
<style>
div.level_ {
margin-left: 00px;
}
div.level_1 {
margin-left: 20px;
}
div.level_2 {
margin-left: 40px;
}
div.level_3 {
margin-left: 60px;
}
div.level_4 {
margin-left: 80px;
}
div.level_5 {
margin-left: 100px;
}
div.level_6 {
margin-left: 120px;
}
div.level_7 {
margin-left: 140px;
}
div.level_8 {
margin-left: 160px;
}
div.level_9 {
margin-left: 180px;
}
div.level_10 {
margin-left: 200px;
}
</style>
I have these columns in the database
id,comment_text, reply_to, sort_order, level, date, ip, visible
And my "clone" or what you can call it simply reads the parent id (reply to) and updates all rows if a comment is addad before. if a comment is addad to the first comment/post, the sort_order is simply +1.
But, how can i output a "comment" inside the post. and a answer
comment inside its parent comment.
Currently it looks like this
EDIT
To make it clear i have prepared some mock up data.
Here is the result I'm looking for: http://jsfiddle.net/wv9j9ueo/
With dis data http://pastie.org/10400764 notice the level column. Shouldn't it be possible to foreach the column levelfrom 0 and then keep going until there is nothing left (notice that the can be two or more of the same value).
If you put divs into the parents your code looks prettiest:
<div class="comment">
<p>The comment</p>
<div class="comment">
<p>The comment</p>
<div class="comment"> <p>The comment</p></div>
</div>
</div>
Css
.comment {
margin-left: 15px;
border-left : 2px dotted blue;
padding : 0 10px;
}
PHP
<?php if(!empty(getMessage())): ?>
<div class="container">
<h1>The nested comment exampel!</h1>
<?php
$i=0; //initialize flag
foreach (getMessage() as $value){ ?>
<div class="comment" id="<?= $value->id; ?>">
//you don't need level class
<?php if($value->visible == 0) : ?>
<?= $value->date ?><br>
Deleted
<?php elseif($value->visible == 1): ?>
<?= $value->date ?> X <?= 'id: '. $value->id . ', sort order: ' .$value->sort_order . ', level: '.$value->level ;?><br>
<?= $value->comment_text ?>
<form action="index.php" method="post">
<input type="hidden" name="id" value="<?= $value->id ?>" />
<input type="hidden" name="parent" value="<?= $value->reply_to ?>" />
Add comment: <input type="text" name="svar">
<input type="submit">
</form>
<?php endif; ?>
<?php
$i++; //sum flag
}
for($x=0; $x<=$i; $x++) { //paint div closers
echo '</div>' ;
}
?>
<? endif; ?>
</div>
See it working
http://jsfiddle.net/jc5104st/1/
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm making a registration form with PHP and I'd like to do something: if user has not completed the form correctly, I want, in addition to the error message, make the inputs (where there is an error) with red borders.
My registration form (HTML part):
<?php if(!empty($errors)): ?>
<div class="flash-message error">
<h3>You have not completed the form correctly. The error(s) come(s) from the following thing(s):</h3>
<ol>
<?php foreach($errors as $error): ?>
<li>
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
</div>
<?php endif; ?>
<h1 class="page-heading"><?php echo $title; ?></h1>
<form action="" method="post">
<ul>
<li>
<label for="nickname">Nickname:</label> <input id="nickname" name="nickname" type="text">
<p class="input-description">Your nickname will be as an identity on the site; it will be displayed wherever you will post, etc.</p>
</li>
<li>
<label for="email">Email:</label> <input id="email" name="email" type="text" placeholder="your#email.com">
<p class="input-description">Enter a valid email to receive the confirmation link to validate your account.</p>
</li>
<li>
<label for="password">Password:</label> <input id="password" name="password" type="password">
<p class="input-description">Enter a password to sign in to your account. Try to put a difficult password to make it more complicated to find.</p>
</li>
<li>
<label for="password-confirmation">Password Confirmation:</label> <input id="password-confirmation" name="password-confirmation" type="password">
<p class="input-description">Confirm the password that you have put in the field above.</p>
</li>
</ul>
<button type="submit" class="button primary">Sign Up</button>
</form>
Current result: http://prntscr.com/86h5r2
PHP code:
<?php
if(!empty($_POST))
{
/* Nickname */
if(empty($_POST["nickname"]))
{
$errors["nickname"] = "You have not completed the nickname field.";
}
elseif(!preg_match("/^[a-zA-Z0-9 _]+$/", $_POST["nickname"]))
{
$errors["nickname"] = "Your nickname is not valid.";
}
/* E-mail */
if(empty($_POST["email"]))
{
$errors["email"] = "You have not completed the email field.";
}
elseif(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
{
$errors["email"] = "Your email is not valid.";
}
/* Password */
if(empty($_POST["password"]))
{
$errors["password"] = "You have not completed the two password fields.";
}
elseif($_POST["password"] != $_POST["password-confirmation"])
{
$errors["password"] = "The passwords did not match. Please enter the same password in both fields.";
}
}
?>
to add a border to the input with error you would want to embed a php if statement like this in the class attributes. just define classname in your css
<input type="text" class="<?= isset($error['name']) ? 'has-error' : '' ?>" value="" >
Adding a style to the <li> is one way
<ol>
<?php foreach($errors as $error): ?>
<li style="border:red solid 1px">
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
A better way would be to create some css and then just add a class to your <li>
<style>
.an-error-msg {
border:red solid 1px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px; /* future proofing */
-khtml-border-radius: 10px; /* for old Konqueror browsers */
}
</style>
<ol>
<?php foreach($errors as $error): ?>
<li class="an-error-msg">
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
Why not just make it client side with the required attribute like this: https://jsfiddle.net/kn7qjg6c/
HTML
<form method="post">
<input type="text" placeholder="name" required/>
<input type="submit" />
</form>
CSS
input:required:focus {
border: 1px solid red;
outline: none;
}
I'm working on some sort of search engine that adds on to a URL to complete the request. using header(Location:http://www.WEBSITENAME.com/'. $search); Although sometimes this will send me to a blank page. Was wondering if there's any sort of code that will redirect me to another page if that error happens. I want the else to be what it redirects to if the page is blank. Thanks.
My code:
search.php
<?php
$search = $_POST["search"];
if(isset($_POST['search'])){
header('Location:http://cydia.saurik.com/package/'.$search);
}else{
?>
<?php
echo "
<head>
<style>
#header{
color:black;
}
.header{
color:black;
font-size:25px;
}
#header_minor{
margin-top:20px;
}
.header_minor{
font-size:18px;
}
a[class='header_minor']{
color:black;
}
body{
text-align:center;
margin-top:14%;
}
#idea{
margin-top:20px;
}
.hidden{
display:none;
visibility:hidden;
}
</style>
</head>
";
?>
<div id="header">
<span class="header">
Sorry, this tweak was not found...
</span>
</div>
<div id="header_minor">
<span class="header_minor">
Would you like to suggest it? or Return home
</span>
</div>
<div id="idea">
<form method="POST" action="idea.php" name="idea">
<input type="text" name="idea" value="<?php echo $_POST['search']; ?>"/>
<input type="text" name="hidden" class="hidden"/>
<input type="submit" value="Submit"/>
</form>
</div>
<?php
exit();
}
?>
It could have been better if you can call an api on that site so that you can interact easier with the external site.
I would do something like this:
PHP:
<?php
if(isset($_POST['search'])) {
$search_text = $_POST['search_field'];
$location_url = "http://cydia.saurik.com/package/{$search_text}/";
$content = #file_get_contents($location_url); // use this function to query on site
if($content) {
// redirect if it has a result
header("Location: {$location_url}");
} else {
// will go here if query on external site is empty (blank)
// create your own empty result page that says your search yielded no results (your own page, redirect the user)
// sample
header("Location: http://www.yoursite.com/index.php?noresults=1");
}
}
?>
HTML:
<form method="POST" action="index.php">
<input type="text" name="search_field" class="" id="" /><br/>
<input type="submit" name="search" class="" id="" value="Search" />
</form>
<?php if(isset($_GET['noresults'])): ?>
<div class="yourdesign" style="display: block; width: 300px; border: 1px solid black;";>
<h1>No results found</h1>
</div>
<?php endif; ?>
I'm pretty new to jQuery Mobile and PHP and I'm having an issue where I have a PHP while loop
while ( $row = sasql_fetch_array ( $idresult ) ) {
echo "
<li>
<a href='#' data-rel='popup' data-position-to='window' data-transition='pop'>
<div class='ui-grid-a'>
<div class='ui-block-a'>
<div class='ui-bar ui-bar-a titleRow' style='height:15px'>Identification Type</div>
<div id='idType' class='ui-bar ui-bar-a 'style='height:15px; background-color:transparent; border: none; color: black; font-weight: normal;' >" . $row ['description'] . "</div>
</div>
<div class='ui-block-b'>
<div class='ui-bar ui-bar-a titleRow' style='height:15px'>Details</div>
<div id='idNo' class='ui-bar ui-bar-a ' style='height:15px; background-color:transparent; border: none; color: black; font-weight: normal;'>" . $row ['number'] . "</div>
</div>
</div>
</a>
<a href='#editCustId' data-rel='popup' data-position-to='window' data-transition='pop'>Edit</a>
</li>
";
} // end while
echo "</ul>";
} // end if
When the use clicks on the edit button I need to pass the ID of that particular row. I'm not sure where I should put this in but it could be something like this...? Will this work when there is no form?
<input type="hidden" name="the_id" value='<?php " . $row ['theid'] . " ?>' />
However I can't figure out how to do this. I have tried opening the dialog as a new page ie.
<a href='./editCustId.php?id=" . $row['theid'] . "' data-rel='popup' data-position-to='window' data-transition='pop' class='ui-btn ui-btn-inline ui-icon-edit ui-btn-icon-notext'>Edit</a>
When edit is clicked this popup will open
<div data-role='popup' id='editCustId' data-theme='a' data-overlay-theme='a' data-dismissible='false' style='min-width: 300px;'>
<div data-role='header' data-theme='a'>
<h1>Add ID</h1>
</div>
<div data-role='main' class='ui-content'>
<form id='editId' onsubmit="return false;">
<input type="hidden" name="cust_id" value='<?php echo $custid; ?>' />
<input type="hidden" name="sess_id" value='<?php echo $sid; ?>' />
<!-- <input type="hidden" name="submitted" value="true" /> -->
<div class="ui-field-contain">
<label for="phoneType">Type</label>
<select name="idType" id="idType">
<?php echo $idInnerOptions; ?>
</select>
</div>
<div class="ui-field-contain">
<label for="idDesc">Description</label> <input type="text" name="idDesc" id="idDesc" value="">
</div>
<div class='ui-grid-a'>
<div class='ui-block-a'>
<input type='submit' id="submit" value='Update' class='ui-btn ui-btn-inline' data-transition='pop' />
</div>
<div class='ui-block-b'>
Cancel
</div>
<div id="success" style="color: black;"></div>
</div>
</form>
</div>
</div>
The description and number will contain the relevant info based on which link was clicked.
I've been looking into passing the data through ajax but I'm not really getting what I should be doing?
I Think there are 2 issues here for you to check more:
As i recall, the popup feature of jquery mobile is for code that are inside divs that has the popup data-role. So, what you tried to do is not in the JQM logic. However, JQM also allows you to use iframe in divs with popup data-role so maybe that will be a good solution for you.
Another way to go, could be to dynamicly load the content of the page you want by AJAX to a div that has the popup data-role.
Hope this helps