Create clickable URL in PHP - php

Trying to create a clickable URL in PHP. If you visit www.wheels4rent.net/test00.html and input location and date clicking the 'quote' will take you to the list_car5.php page. At right of this page is a 'book now' button that does not work and the text hyperlink below this. problem is when clicking the text hyperlink instead of giving me the www.thrifty.co.uk URL it gives me www.wheels4rent.net/www.thrifty.co.uk URL which obviously does not display webpage. Please assist. Also i need to also create the text hyperlink within my 'book now' button instead. below is code
$url = (string)$car->book;
echo "<tr><td width=200px><' align='right' style='padding:1px; width:100px'><b>".$car->cartype."</b><br>".$car->carsipp."<br>".$car->transmission."</td><td><b>".$car->carexample."</b></td><td><b>£".$car->price."
</b><br>Unlimited Miles</b><br><a href='$url'><input type='submit' name='Book Now' value='Book Now'><br>book now<br></a></td></tr>";
}
echo "</table>";

You need to add http:// to the beginning of the URL in the <a> tag. I can't even read the code you've posted, so that's the only answer I can give.

Instead of wrapping your in an , use the onclick attribute of the tag.
<input type='submit' name='Book Now' value='Book Now'
onclick="javascript:window.location('http://www.thrifty.co.uk')" />
Book Now

single quotes doesn't read variables.
So you could either write the whole html part in echo or you can simply close the php tag and enter the html code and then continue with your php code
for ex:
<?php
echo "<input type='submit' value='submit' onclick='<script>window.location('http://www.google.com')</script>'";
?>
or simply:
<?php
-----//php code here
----
----
?>
<input type="submit" value="submit" onclick="<script>window.location('http://www.google.com')</script>"/>
<?php
------
------
------
?>

Related

Input div id into text box and delete it from a text file when submit is pressed

I have been racking my brain trying to get a very particular function to work. It seems simple but I just cant figure it out. I am looking to basically get a txt file and allow someone to type in a certain id into an input box that upon the user clicking "delete" will remove only the targeted DIV id.
I have tried wrapping a PHP file around a form with no success, as well as putting the PHP directly into the submit button but nothing has worked, can anyone point me in the correct direction?
I have looked for other post here but nothing seems to be exactly what im looking for or I am wording it incorrectly. This is essentially how I want it to look:
<form action='delete.php' method='post'>
<input name='idinput' type='text' value='Enter The Certain ID Value You Want To Remove'>
<input type='submit' name='submit' value='Remove'>
</form>
Not sure about the text file bit but to remove an element from the DOM, well, you can't do this in PHP without reloading the page and apssing in some extra data na dusing some logic to not display that element...
You need to use JavaScript... or with JS with jQuery
$(function(){
$('input[name="submit"]').on('click', function() {
var val = $('input[name="idinput"]').val();
$('#or.IDorCLASSNAME_' + val).remove(); //If Id Input val is 3 this gives #or.IDorCLASSNAME_3
});
});
jQuery: https://api.jquery.com
jQuery Remove: https://api.jquery.com/remove/
jQuery DOM Removal: https://api.jquery.com/category/manipulation/dom-removal/
Tutorial: https://www.w3schools.com/jquery/jquery_dom_remove.asp
I was able to do this by placing a form that is inserted within the txt info im submitting:
<form action='delete.php' method='post'>
<input type='hidden' name='random' id='random' value='".$random."'>
<button type='submit' value='report'></button>
</form>
And also by adding this to the delete.php page:
<?php
$random = $_POST['random'];
$original = "<div id='".$random."'>";
$replacement = "<div id='".$random."' class='hidden'>";
$str = file_get_contents('submissions.txt');
$str = str_replace("$original", "$replacement",$str);
file_put_contents('submissions.txt', $str);
header('Location: index.php');
?>

Redirecting cancel button to url

I have the following code which is causing me problem. The code generates two buttons, one to remove the selected project and the other to cancel the deletion of the project. The remove function works well, however I haven't found a way to make my cancel button redirect to my url (when I click on it, nothing happens). Any clue?
...
echo "<form method='post'>";
echo "<input type='hidden' value='".$currentid."' name='project'/>";
echo "<b>".$project_name."</b>";
?>
<div class="btn_2"> <input type="submit" name="save" value="Remove"><input type="submit" onclick="window.location.replace('www.myurl.ca')" value="Cancel"></div>
</form>
You're using a submit button and tagging JS on to it. I'm expecting that you're actually submitting the form, but I could be wrong.
If nothing is happening with your JS, you may try doing window.location.href = "www.myurl.ca"; return false; where including the return false should avoid the submit.
The best solution would probably be to make it a plain button and wrap it in an A tag. You would avoid submitting your form, redirect, and all without requiring JS be active.
...
echo "<form method='post'>";
echo "<input type='hidden' value='".$currentid."' name='project'/>";
echo "<b>".$project_name."</b>";
?>
<div class="btn_2"> <input type="submit" name="save" value="Remove"><button type="button">Cancel</button></div>
</form>
Using the formaction button attribute works.
<input type="submit" name="save" value="Cancel" formaction="http://www.myurl.ca">

Can I self submit back to a textarea box?

I am able to create a textarea box that will accept text and store that text to the $_POST super global, but I can't get the text to "come back" to the box once I submit it. (The form is self submitting). If I run a simple echo on the submitted data, however, it displays fine (as shown toward the end of the script below.
<!DOCTYPE html> <body> <?php require("Connection_to_WS.php");
echo ("<form action='Edit_Thread_Description.php' method='post'>");
IF (ISSET($_POST['revised_thread_descr'])) {
$revised_thread_descr=($_POST['revised_thread_descr']);
ECHO "Edit the Revised_Thread_Description here: <br> <textarea name='revised_thread_descr' rows='5' cols='50' value= $_POST[revised_thread_descr]"; // Fails to return any text on Submit.
?><p></textarea></p><br><?php
}
ELSE {$revised_thread_descr= '[some default]';
ECHO "Edit the Revised_Thread_Description here: <br> <textarea name= 'revised_thread_descr' rows='5' cols='50' value= $revised_thread_descr";
?><p></textarea></p><br><?php
}
ECHO '<br>';
echo $_POST['revised_thread_descr']; // Succeeds in returning POST text from the textarea box upon Submit (but outside of the textarea box).
ECHO '<br>';
echo "Click 'Submit': <input type='Submit' name='submit' value='Submit'/>";
echo '<br>';
mysqli_close($connection);
?>
</body> </html>
Doing the same sort of thing was a breeze using "<input type", but I've sunk hours into getting <textarea to cooperate. I I'd be grateful for any assistance.
As Ann Sophie said, there is no "value" property on the textarea element
(https://www.w3schools.com/tags/tag_textarea.asp)
if you want to dynamically append content to it, you can use :
<?php if (isset($_POST['revised_thread_descr'])): ?>
<textarea><?= $_POST['revised_thread_descr'] ?></textarea>
<?php else: ?>
//
Note that you have to echo it, in my example I used alternative syntax,
(http://php.net/manual/fr/control-structures.alternative-syntax.php)
which I think is much more cleaner when you works with PHP + HTML
<?= XXX ?> is short for <?php echo XXX; ?>
I botched a response via 'comment', above. This continues that comment:
This code works, but won't repopulate the box with remarks submitted back to the script via the POST super global.
IF(ISSET($_POST['revised_thread_descr'])):
$revised_thread_descr=($_POST['revised_thread_descr']); ?>
<p> Revised_thread_descr - Edit here:</p><textarea
name='revised_thread_descr' rows='5' cols='50'
<p></textarea></p><br>
<?php
ELSE:
$revised_thread_descr= '[some default]'; ?>
<p> Revised_thread_descr - Edit here:</p><textarea name= 'revised_thread_descr' rows='5' cols='50'
<p></textarea></p><br>
<?php
ENDIF;
echo "Click 'Submit': <input type='Submit' name='submit' value='Submit'/>";
echo '<br>';
mysqli_close($connection);
?>
</body>
</html>
This code, with just a slightly different placement of the <p> tags, gobbles up and displays all html material that comes after the closing </textarea> tag.
IF(ISSET($_POST['revised_thread_descr'])):
$revised_thread_descr=($_POST['revised_thread_descr']); ?>
<p> Revised_thread_descr - EDIT HERE:</p><p><textarea name= 'revised_thread_descr' rows='5' cols='50'
</textarea></p><br>
<?php
As in the screenshot of the browser rendering, below.
Thanks, btw, for getting me to try that alternate syntax! Less confusing.
Bless you! I'd given up and was going for a workaround. I put in that tag caret as you suggested and it all worked. Here is the gist of it, with everything working, and the textarea box populating correctly. Thank you so much for your patience and persistence. Tell me it gets easier... .
<!DOCTYPE html> <body>
<?php
echo ("<form action='Textarea_Example.php' method='post'>");
// The first IF only executes after the script has run once and created a POST value. On the second run, the first IF executes and successfully populates the textarea box with the latest POSTed value
IF (ISSET($_POST['revised_thread_descr'])): ?>
<p>Edit current thread description:<p>
<textarea name= 'revised_thread_descr' rows='5' cols='50'>
<?php echo $_POST['revised_thread_descr'] ?>
</textarea>
<?php ELSE:
$revised_thread_descr = 'some default'; ?>
<p>Edit current thread description:<p>
<p><textarea name= 'revised_thread_descr' rows='5' cols='50'>
The textarea box opens with this in it, but only on the first run. Then it successfully switches to the value typed to the textarea box and saved to POST
</textarea>
<?php ENDIF; ?>
</p>
<?php
// here's the submit button
echo "Click 'Submit': <input type='Submit' name='submit' value='Submit'/>";
?>
</body> </html>

Activate action onClick in PHP

I have the following chunk of code:
while ($row = mysql_fetch_array($result)) {
echo "<li/>".$row['trendName']."<input type='submit' name='Dispay' value='Display All Items' onclick='action='http://blah.co.uk/DisplayData.php';'/>";
echo"<br />";
}
So, this I want to do is for each element on the list to create a button. When I will click at this button I want to hit a URL.
Let's say that we have only one element on the list (Movies). By clicking on the button next to the movies, I want to move to another URL: http://blah.co.uk/DisplayData.php
and furthermore to pass to the other URL the name of the element (i.e. Movies)
Is this possible, and if so, how?
I would also recommend to use <button></button> in html 5 to create a button.
echo "<button type='submit' name='Display' onclick='javascript:location=\"http://blah.co.uk/DisplayData.php?value=$row['trendName']\"'>Display</button>";
As suggested above, a link is the proper way to do so.
<?php echo "<a href='http://blah.co.uk/DisplayData.php?value=".$row['trendName']."'>Display</a>"; ?>
You can use $_GET['value']; to retrieve your data "trendName"
However "action" is used in the <form></form> tag
<form action='http://blah.co.uk/DisplayData.php'>
<input type='hidden' name='value' value='<?php echo $row['trendName']; ?>' />
<button type='submit'>Display</button>
</form>
here you would use $_POST['value']; to retrieve your data "trendName"
onclick="this.location.href='http://blah.co.uk/DisplayData.php?value=' + $row['trendName']"
If you tell, where "someValue" should come from, I'll edit this code later.
However, I would recommend using a link instead.

how to post special character and symbol using php

I am new one in php.I was just create a form for sending special character and symbol using .I got for get the text
<form name='form1' method='post' action='s.php'>
<textarea name='ask' id='ask' style=' resize:none ; border: #093; height:250px; width:350px'></textarea><input type="submit" name="button" id="button" value="Submit" /></td>
</form>
this is form and s.php is
<?php
$ask=$_POST['ask'];
echo $ask;
?>
inputed value
#include<iostream.h>
but i got only
#include
why did i got output like this ? and any method to get full text . Please help me anyone
Right click and view the page source. The <iostream.h> is being interpreted as an HTML tag by your browser.
Passing the value through htmlentities() will make it work as expected:
$ask = $_POST['ask'];
echo htmlentities($ask);

Categories