I have a user form that creates a drop down menu in Wordpress php. The form clears after it's submitted. How can I re-populate the form, when the edit pencil icon is clicked so the original info can be edited? As it is, because the form is cleared, it starts another menu.
There is one category and multiple names.
Thank you...if you need info, I will post it. I'm trying...
-A
I'm having a problem with this...as I mentioned, there is an "edit button" that creates a stupid edit form that some guy designed. I would like to repopulate the original form users filled out. I'm almost there. The info is is filled in boxes but they randomly overlay the drop down menu. It's not hitting inside the original form. "pp-website-edit" is the name of the "edit button".
<div class="pp-website-edit">
<form id="cat-edit-<?php echo $x; ?>" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="edit-category" value="<?php echo $indicat; ?>">
<INPUT TYPE="image" SRC="<?php bloginfo('url'); ?>/wp-content/themes/nebula/neb-style/images/arrow_045_small.png" HEIGHT="14" WIDTH="14" BORDER="0" ALT="Submit Form">
</form>
</div>
<div class="pp-website-edit">
<form id="wat-edit" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="edit-website" value="1">
<input type="hidden" name="ed-w-cat" value="<?php echo $indicat; ?>">
<input type="hidden" name="ed-w-label" value="<?php echo $finalresult[$y][name]; ?>">
<input type="hidden" name="ed-w-url" value="<?php echo $finalresult[$y][url]; ?>">
<INPUT TYPE="image" SRC="<?php bloginfo('url'); ?>/wp-content/themes/nebula/neb-style/images/arrow_045_small.png" HEIGHT="14" WIDTH="14" BORDER="0" ALT="Submit Form">
</form>
============================================================================
Site Category
Site Titles
Website url's
Forms that keep their values utilize some sort of peristance, either cookies, or a combination of querying the database for the values.
Either way you would need to then echo our the value inside the <input> tag.
Related
I am displaying list of items(multiple entries) from database on one page. I am trying to post all those values fetched from the database to another php file to add item to cart.
But when I press 'add to cart' button for any item in the list, it is only sending last item through POST. I know it is because of while loop, but I don't know correct way to implement it?
<form action="php/addToCart.php" method= "POST">
<?php
while($product=mysqli_fetch_assoc($featured)):
?>
<div class="col-md-5">
<h4><?= $product['title'] ?></h4>
<image src="php/marketplace_images/<?= $product['image'];?>" alt="<?= $product['title'];?>" height="300" width="300"/>
<p class="lprice"> Price $ <?= $product['price'];?></p>
<p class="desc"> Description: <?= $product['description'];?></p>
<p class="bname"> Brand Name: <?= $product['brandname'];?></p>
<input name="title" type="hidden" value="<?= $product['title'] ?>" />
<input name="price" type="hidden" value="<?= $product['price'] ?>" />
<input name="brandname" type="hidden" value="<?= $product['brandname'] ?>" />
<input name="image" type="hidden" value="<?= $product['image'] ?>" />
<input name="featured" type="hidden" value="<?= $product['featured'] ?>" />
<button type="submit" class="btn btn-success" data-toggle="modal" name="add">Add To Cart</button>
</div>
<?php endwhile;
?>
You're ending up with a single form with n (as many as items) fields with the same name, that are no longer separate. E.g. you'll have n fields named "title", n fields named "price" etc.
You'd never know which title belongs to which price.
Plus, the code you show only shows the rendering of the form, not what you're doing with it on submission (but that wouldn't make it better, as you can't distinguish between all the different inputs). If that code expects one title, it might take the last, or a random one.
So, if you want to send just a single item: Move your <form> and </form> into the while loop, so that you end up with a number of forms that can be individually submitted. In general I'd recommend against posting all of the data and just limit yourself to an id of an item, but that's beyond the scope of this question (but imagine what happens when I manipulate the price to 0 before submitting the item to the cart)
So if someone is logged in my script reads the values and stores it and sets it as variables then I'm trying to make a registration page for something that members can register in.
The script is simple
<div id="english1"><p id="english1p">تأكد من بياناتك ثم اضغط رز الموافقة</p><br>
<form class="register2" action="includes/register2.inc.php" method="post" name="register2form"
<p class="username">اسم المستخدم: <?php echo htmlentities($_SESSION['username']); ?></p>
<p class="email">الايميل: <?php echo htmlentities($_SESSION['email']); ?></p>
<p class="age">السن: <?php echo htmlentities($_SESSION['age']); ?></p>
<p class="coursetype">الكورس المراد التسجيل فيه: <?php echo $coursename; ?></p>
<p class="paymethod">طرق الدفع:</p><ol><li>طريقة</li>
<li>طريقة</li>
<li>طريقة</li>
</ol>
<p class="sure">للتأكيد اضغط تسجيل</p>
<input class="register2button"
type="button"
value="تسجيل"
onclick="" />
</div>
Ignore the letters you don't understand, it's arabic.
So the script reads variables and then I want when the member clicks the submit button, the page POST the variables to includes/register2.inc.php without input as the variables are already set.
How can I do that?
If you want to keep your <p> tags you can store all the variables you want to pass to the next page in <input type="hidden" value="some value" /> These boxes will not be shown on the page, but will pass along data with any request you send to your server.
You can store your value in hidden element and pass it to next page.
<form action="page name" method="post">
<input type="hidden" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>" />
<p class="username"> username : <?php echo htmlentities($_SESSION['username']); ?></p>
<input type="submit" name="submit" value="submit" >
</form>
Inside the form, instead of p you should use input for each parameter:
<input type="text" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>"/>
You can kept this input hidden also like:
<input type="hidden" name="username" value="yourvalue"/>
These input field value won't pass in next page in $_POST if you will use p you have to use input for this.
I have the following form to upload images of my products, this works great in Firefox and Chrome, but in Internet Explorer images are NOT uploaded and instead of uploading images, I am being redirected to my www.myhomepage.com/index.php instead of submitting the form elements and remaining in the same url which in Chrome is something like: /index.php?view=user&task=editi&productid=3872, which is the link I have in firefox address bar after submitting the form.
I think some form field is not passed to internet explorer but I cant find the reason.
this is the code of the form:
<form action="index.php" method="post" name="ImageForm" id="ImageForm" enctype="multipart/form-data">
<div id="botones_form" style="width:100%; float:right;">
<input name="files" type="file" id="files" class="files" />
</div>
<input class="save" type="submit" name="boton" value="<?php echo JText::_( 'Upload Images' ); ?>" />
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="parent" value="<?php echo $product_id; ?>" />
<input type="hidden" name="task" value="save" />
<input type="hidden" name="controller" value="images" />
</form>
Do you see anything wrong with this code? What could be the problem? I am no programmer, so I dont know if you need more details in order to help me, but please feel free to ask more code of the php file where the form is located or code of any called controller...
I have build a system to put together a shed, this is done with several pages with radio buttons and forms.
The problem is that with this form i use action and POST to send the result to the next page.
But i want the input for example on page 1 to be send to page 2 and 3, currently thats impossible because you can only have one action in your form.
<form action="lounge-kamer3.php" method="POST">
I need the input from page 1 for an if statement on page 2 and 3. how do i do that?
Couldnt find an easy way on the internet, and because i do not master english that well it sometimes is hard to understand.
Hope i am clear enough.
ps. sorry for my english, not my first language.
Perhaps try using a hidden field, a cookie, or session info to carry information across pages.
How to pass information across web pages of a web site
You might want to write the requests asynchronously and then you can continually reuse info on the page with js and php.
You should use hidden fields.
In page 1, let's say 2 have 2 fields, in page 2, you have other 2 fields, but you actually have 4: 2 visible, and 2 hidden. These hidden fields must have the value: the $_POST['field1']
Example:
Page1.php:
<form action="page2.php" method="POST">
<input type="text" name="one">
<input type="submit">
</form>
page2.php:
<form action="page3.php" method="POST">
<input type="hidden" name="one" value="<?php echo $_POST['one']; ?>">
<input type="text" name="two">
<input type="text" name="three">
<input type="submit">
page3.php:
<form action="end.php" method="POST">
<input type="hidden" name="one" value="<?php echo $_POST['one']; ?>">
<input type="hidden" name="two" value="<?php echo $_POST['two']; ?>">
<input type="hidden" name="three" value="<?php echo $_POST['three']; ?>">
<input type="text" name="four">
<input type="submit">
</form>
end.php
<?php
echo $_POST['one'];
echo $_POST['two'];
echo $_POST['three'];
echo $_POST['four'];
?>
http://www.echoecho.com/htmlforms07.htm
http://www.tizag.com/htmlT/htmlhidden.php
hidden field in php
Currently, I am working on a site that uses PayPal to Checkout. I would like to enable stripe, as well, so there can be a "checkout with stripe" button at the bottom of the form.
<form method="POST" id="form1" >
<select id="udidSelect" onchange="udidPrice(this)">
<option value="invalid" disabled="disabled">Choose Package</option>
<option value="udid">UDID Registration</option>
<option value="profile">UDID Registration & Free Unlimited Apps (Provisioning Profile)</option>
</select><br />
<br />
<input type="text" placeholder="Name" /><br />
<br />
<input type="email" placeholder="Email" /><br />
<br />
<input type="text" placeholder="UDID (40 Characters Long)" name="os0" /> <br />
<input type="hidden" name="on0" value="UDID">
<br />
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" id="udidbuttonID" value="9PSTCESRS3FSG">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" value="PayPal" onclick="submitForm('https://www.paypal.com/cgi-bin/webscr')" style="float:right;">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Now I would like to have a PayPal Button at the bottom of the form and a Stripe button at the bottom of the form. And if the user clicked the stripe button, it would take them to the next page and PASS ALONG the information entered in this page. I am not sure how to do this, and I am also not sure how to have different post options for the form. (Sorry I am kind of new to this.)
On the stripe checkout page, also, how would I request that information that was passed along, from the previous form. Would it just be something like this?
<input type="hidden" name="somedata" value="<?php echo $_POST['somedata']; ?>" />
<input type="hidden" name="otherdata" value="<?php echo $_POST['otherdata']; ?>" />
If I'm reading your question correctly, you want the form to go to different pages depending on whether the user clicked on Stripe or Paypal.
You can use JavaScript/jQuery to change the action attribute of the form:
<!--HTML-->
<button onClick="setFormAction('stripe')">Stripe</button>
<button onClick="setFormAction('paypal')">Paypal</button>
//Javascript
function setFormAction(which) {
if (which == 'stripe') {
//Change 'stripe.php' to the proper URL
document.getElementById('form1').action = 'stripe.php';
} else {
document.getElementById('form1').action = 'paypal.php'; //Change this also
}
//Finally, submit the form
document.getElementById('form1').submit();
}
Or, more understandably, the jQuery solution:
<!--HTML-->
<button id="stripe">Stripe</button>
<button id="paypal">Paypal</button>
//Javascript
$('button#stripe').click(function() {
$('form#form1')
.attr('action', 'stripe.php') //Change to proper stripe URL
.submit();
});
$('button#paypal').click(function() {
$('form#form1')
.attr('action', 'paypal.php') //Change to paypal URL
.submit();
});
On the next page, you do exactly what you said previously:
<input type="hidden" name="somedata" val="<?php echo $somedata; ?>" />
Always sanitize user-inputted values before echoing them on the page (therefore the variable $somedata rather than $_POST['somedata'].
An alternative to hidden input fields is sessions. Much easier to handle once you get the hang of it.
Add another line as:
test.php is the page where you want to post this form
<input type="button" border="0" value="Pay with Stripe" onclick="submitForm('test.php')">
in test.php you can get the values like this:
<input type="hidden" name="test" value="<?php echo $_REQUEST['test'] ?>">