开发者

PHP in MVC, create link dynamically

开发者 https://www.devze.com 2023-04-02 18:32 出处:网络
I have some input fields in my View. I want a link to be generated dynamically based off the user\'s input into these fields.

I have some input fields in my View. I want a link to be generated dynamically based off the user's input into these fields.

My understanding is that normally, php cannot be updated after the page is rendered, but for some reason I think this is different in an MVC setup??

My solution - based on this assumption - is to store a php variable in the user input field. And call that variable where my link is generated.

example: the input field, I want to store the input text into new variable $locationhold

<dt><label for="location_area" class="required">Area</label></dt>
    <dd><input type="text" name="location_area" id="location_area" value="<?php if($this->validation->location_area){ echo $this->validation->location_area; $locationhold=$this->validation->location_area; }else echo $property->location_area; ?>" class="required" /></dd>

and then somehow summon $locationhold and make it part of this link:

<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.mysite.com/item/listing/<?php echo $locationhold ?>"  data-text="NEW POST!" data-count="none">Tweet</a>

anyway this doesn't quite work, tips? the <?p开发者_开发问答hp echo ?> is ignored. My tweet says "New Post! http://www.mysite.com/item/listing/" and not the rest of the information that I wanted to dynamically append to the link. This may be because by the time the page rendered, $locationhold was still empty, but how can I retain a user modified value in it and achieve the result I am looking for


You need to post the user input to you server before transmitting to twitter. You would have your form post to your server where you would configure the locationhold, then you would configure your request to twitter and send the information along from the server instead of the client.

Alternatively you could use ajax to submit the necessary info to figure out your locationhold to the server when the inputs are completed in the form, then inject the configured URL into the form client side before the user submits it to twitter.

0

精彩评论

暂无评论...
验证码 换一张
取 消